tbytevector.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     copyright            : (C) 2002 - 2008 by Scott Wheeler
00003     email                : wheeler@kde.org
00004  ***************************************************************************/
00005 
00006 /***************************************************************************
00007  *   This library is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU Lesser General Public License version   *
00009  *   2.1 as published by the Free Software Foundation.                     *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful, but   *
00012  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the Free Software   *
00018  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA         *
00019  *   02110-1301  USA                                                       *
00020  *                                                                         *
00021  *   Alternatively, this file is available under the Mozilla Public        *
00022  *   License Version 1.1.  You may obtain a copy of the License at         *
00023  *   http://www.mozilla.org/MPL/                                           *
00024  ***************************************************************************/
00025 
00026 #ifndef TAGLIB_BYTEVECTOR_H
00027 #define TAGLIB_BYTEVECTOR_H
00028 
00029 #include "taglib.h"
00030 #include "taglib_export.h"
00031 
00032 #include <vector>
00033 #include <iostream>
00034 
00035 namespace TagLib {
00036 
00038 
00045   class TAGLIB_EXPORT ByteVector
00046   {
00047   public:
00048 #ifndef DO_NOT_DOCUMENT
00049     typedef std::vector<char>::iterator Iterator;
00050     typedef std::vector<char>::const_iterator ConstIterator;
00051     typedef std::vector<char>::reverse_iterator ReverseIterator;
00052     typedef std::vector<char>::const_reverse_iterator ConstReverseIterator;
00053 #endif
00054 
00058     ByteVector();
00059 
00064     ByteVector(uint size, char value = 0);
00065 
00069     ByteVector(const ByteVector &v);
00070 
00074     ByteVector(const ByteVector &v, uint offset, uint length);
00075 
00079     ByteVector(char c);
00080 
00084     ByteVector(const char *data, uint length);
00085 
00092     ByteVector(const char *data);
00093 
00097     virtual ~ByteVector();
00098 
00102     ByteVector &setData(const char *data, uint length);
00103 
00108     ByteVector &setData(const char *data);
00109 
00117     char *data();
00118 
00122     const char *data() const;
00123 
00129     ByteVector mid(uint index, uint length = 0xffffffff) const;
00130 
00135     char at(uint index) const;
00136 
00143     int find(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
00144 
00151     int find(char c, uint offset = 0, int byteAlign = 1) const;
00152 
00159     int rfind(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
00160 
00168     bool containsAt(const ByteVector &pattern, uint offset, uint patternOffset = 0, uint patternLength = 0xffffffff) const;
00169 
00173     bool startsWith(const ByteVector &pattern) const;
00174 
00178     bool endsWith(const ByteVector &pattern) const;
00179 
00184     ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
00185 
00196     int endsWithPartialMatch(const ByteVector &pattern) const;
00197 
00201     ByteVector &append(const ByteVector &v);
00202 
00206     ByteVector &clear();
00207 
00211     uint size() const;
00212 
00218     ByteVector &resize(uint size, char padding = 0);
00219 
00223     Iterator begin();
00224 
00228     ConstIterator begin() const;
00229 
00233     Iterator end();
00234 
00238     ConstIterator end() const;
00239 
00243     ReverseIterator rbegin();
00244 
00248     ConstReverseIterator rbegin() const;
00249 
00253     ReverseIterator rend();
00254 
00258     ConstReverseIterator rend() const;
00259 
00266     bool isNull() const;
00267 
00274     bool isEmpty() const;
00275 
00279     uint checksum() const;
00280 
00291     uint toUInt(bool mostSignificantByteFirst = true) const;
00292 
00303     uint toUInt(uint offset, bool mostSignificantByteFirst = true) const;
00304 
00316     uint toUInt(uint offset, uint length, bool mostSignificantByteFirst = true) const;
00317 
00327     short toShort(bool mostSignificantByteFirst = true) const;
00328 
00338     short toShort(uint offset, bool mostSignificantByteFirst = true) const;
00339 
00349     unsigned short toUShort(bool mostSignificantByteFirst = true) const;
00350 
00360     unsigned short toUShort(uint offset, bool mostSignificantByteFirst = true) const;
00361 
00372     long long toLongLong(bool mostSignificantByteFirst = true) const;
00373 
00384     long long toLongLong(uint offset, bool mostSignificantByteFirst = true) const;
00385 
00395     static ByteVector fromUInt(uint value, bool mostSignificantByteFirst = true);
00396 
00405     static ByteVector fromShort(short value, bool mostSignificantByteFirst = true);
00406 
00416     static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true);
00417 
00421     static ByteVector fromCString(const char *s, uint length = 0xffffffff);
00422 
00426     const char &operator[](int index) const;
00427 
00431     char &operator[](int index);
00432 
00436     bool operator==(const ByteVector &v) const;
00437 
00441     bool operator!=(const ByteVector &v) const;
00442 
00447     bool operator==(const char *s) const;
00448 
00453     bool operator!=(const char *s) const;
00454 
00460     bool operator<(const ByteVector &v) const;
00461 
00465     bool operator>(const ByteVector &v) const;
00466 
00470     ByteVector operator+(const ByteVector &v) const;
00471 
00475     ByteVector &operator=(const ByteVector &v);
00476 
00480     ByteVector &operator=(char c);
00481 
00485     ByteVector &operator=(const char *data);
00486 
00491     static ByteVector null;
00492 
00496     ByteVector toHex() const;
00497 
00498   protected:
00499     /*
00500      * If this ByteVector is being shared via implicit sharing, do a deep copy
00501      * of the data and separate from the shared members.  This should be called
00502      * by all non-const subclass members.
00503      */
00504     void detach();
00505 
00506   private:
00507     class ByteVectorPrivate;
00508     ByteVectorPrivate *d;
00509   };
00510 }
00511 
00516 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
00517 
00518 #endif