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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00019  *   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 #endif
00052 
00056     ByteVector();
00057 
00062     ByteVector(uint size, char value = 0);
00063 
00067     ByteVector(const ByteVector &v);
00068 
00072     ByteVector(char c);
00073 
00077     ByteVector(const char *data, uint length);
00078 
00085     ByteVector(const char *data);
00086 
00090     virtual ~ByteVector();
00091 
00095     ByteVector &setData(const char *data, uint length);
00096 
00101     ByteVector &setData(const char *data);
00102 
00110     char *data();
00111 
00115     const char *data() const;
00116 
00122     ByteVector mid(uint index, uint length = 0xffffffff) const;
00123 
00128     char at(uint index) const;
00129 
00136     int find(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
00137 
00144     int rfind(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
00145 
00153     bool containsAt(const ByteVector &pattern, uint offset, uint patternOffset = 0, uint patternLength = 0xffffffff) const;
00154 
00158     bool startsWith(const ByteVector &pattern) const;
00159 
00163     bool endsWith(const ByteVector &pattern) const;
00164 
00169     ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
00170 
00181     int endsWithPartialMatch(const ByteVector &pattern) const;
00182 
00186     ByteVector &append(const ByteVector &v);
00187 
00191     ByteVector &clear();
00192 
00196     uint size() const;
00197 
00203     ByteVector &resize(uint size, char padding = 0);
00204 
00208     Iterator begin();
00209 
00213     ConstIterator begin() const;
00214 
00218     Iterator end();
00219 
00223     ConstIterator end() const;
00224 
00231     bool isNull() const;
00232 
00239     bool isEmpty() const;
00240 
00244     uint checksum() const;
00245 
00256     uint toUInt(bool mostSignificantByteFirst = true) const;
00257 
00267     short toShort(bool mostSignificantByteFirst = true) const;
00268 
00279     long long toLongLong(bool mostSignificantByteFirst = true) const;
00280 
00290     static ByteVector fromUInt(uint value, bool mostSignificantByteFirst = true);
00291 
00300     static ByteVector fromShort(short value, bool mostSignificantByteFirst = true);
00301 
00311     static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true);
00312 
00316     static ByteVector fromCString(const char *s, uint length = 0xffffffff);
00317 
00321     const char &operator[](int index) const;
00322 
00326     char &operator[](int index);
00327 
00331     bool operator==(const ByteVector &v) const;
00332 
00336     bool operator!=(const ByteVector &v) const;
00337 
00342     bool operator==(const char *s) const;
00343 
00348     bool operator!=(const char *s) const;
00349 
00355     bool operator<(const ByteVector &v) const;
00356 
00360     bool operator>(const ByteVector &v) const;
00361 
00365     ByteVector operator+(const ByteVector &v) const;
00366 
00370     ByteVector &operator=(const ByteVector &v);
00371 
00375     ByteVector &operator=(char c);
00376 
00380     ByteVector &operator=(const char *data);
00381 
00386     static ByteVector null;
00387 
00388   protected:
00389     /*
00390      * If this ByteVector is being shared via implicit sharing, do a deep copy
00391      * of the data and separate from the shared members.  This should be called
00392      * by all non-const subclass members.
00393      */
00394     void detach();
00395 
00396   private:
00397     class ByteVectorPrivate;
00398     ByteVectorPrivate *d;
00399   };
00400 
00401 }
00402 
00407 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
00408 
00409 #endif