tbytevector.h
Go to the documentation of this file.
1 /***************************************************************************
2  copyright : (C) 2002 - 2008 by Scott Wheeler
3  email : wheeler@kde.org
4  ***************************************************************************/
5 
6 /***************************************************************************
7  * This library is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU Lesser General Public License version *
9  * 2.1 as published by the Free Software Foundation. *
10  * *
11  * This library is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the Free Software *
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19  * 02110-1301 USA *
20  * *
21  * Alternatively, this file is available under the Mozilla Public *
22  * License Version 1.1. You may obtain a copy of the License at *
23  * http://www.mozilla.org/MPL/ *
24  ***************************************************************************/
25 
26 #ifndef TAGLIB_BYTEVECTOR_H
27 #define TAGLIB_BYTEVECTOR_H
28 
29 #include "taglib.h"
30 #include "taglib_export.h"
31 
32 #include <vector>
33 #include <iostream>
34 
35 namespace TagLib {
36 
38 
46  {
47  public:
48 #ifndef DO_NOT_DOCUMENT
49  typedef std::vector<char>::iterator Iterator;
50  typedef std::vector<char>::const_iterator ConstIterator;
51 #endif
52 
56  ByteVector();
57 
62  ByteVector(uint size, char value = 0);
63 
67  ByteVector(const ByteVector &v);
68 
72  ByteVector(char c);
73 
77  ByteVector(const char *data, uint length);
78 
85  ByteVector(const char *data);
86 
90  virtual ~ByteVector();
91 
95  ByteVector &setData(const char *data, uint length);
96 
101  ByteVector &setData(const char *data);
102 
110  char *data();
111 
115  const char *data() const;
116 
122  ByteVector mid(uint index, uint length = 0xffffffff) const;
123 
128  char at(uint index) const;
129 
136  int find(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
137 
144  int rfind(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
145 
153  bool containsAt(const ByteVector &pattern, uint offset, uint patternOffset = 0, uint patternLength = 0xffffffff) const;
154 
158  bool startsWith(const ByteVector &pattern) const;
159 
163  bool endsWith(const ByteVector &pattern) const;
164 
169  ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
170 
181  int endsWithPartialMatch(const ByteVector &pattern) const;
182 
186  ByteVector &append(const ByteVector &v);
187 
191  ByteVector &clear();
192 
196  uint size() const;
197 
203  ByteVector &resize(uint size, char padding = 0);
204 
208  Iterator begin();
209 
213  ConstIterator begin() const;
214 
218  Iterator end();
219 
223  ConstIterator end() const;
224 
231  bool isNull() const;
232 
239  bool isEmpty() const;
240 
244  uint checksum() const;
245 
256  uint toUInt(bool mostSignificantByteFirst = true) const;
257 
267  short toShort(bool mostSignificantByteFirst = true) const;
268 
278  unsigned short toUShort(bool mostSignificantByteFirst = true) const;
279 
290  long long toLongLong(bool mostSignificantByteFirst = true) const;
291 
301  static ByteVector fromUInt(uint value, bool mostSignificantByteFirst = true);
302 
311  static ByteVector fromShort(short value, bool mostSignificantByteFirst = true);
312 
322  static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true);
323 
327  static ByteVector fromCString(const char *s, uint length = 0xffffffff);
328 
332  const char &operator[](int index) const;
333 
337  char &operator[](int index);
338 
342  bool operator==(const ByteVector &v) const;
343 
347  bool operator!=(const ByteVector &v) const;
348 
353  bool operator==(const char *s) const;
354 
359  bool operator!=(const char *s) const;
360 
366  bool operator<(const ByteVector &v) const;
367 
371  bool operator>(const ByteVector &v) const;
372 
376  ByteVector operator+(const ByteVector &v) const;
377 
381  ByteVector &operator=(const ByteVector &v);
382 
386  ByteVector &operator=(char c);
387 
391  ByteVector &operator=(const char *data);
392 
397  static ByteVector null;
398 
402  ByteVector toHex() const;
403 
404  protected:
405  /*
406  * If this ByteVector is being shared via implicit sharing, do a deep copy
407  * of the data and separate from the shared members. This should be called
408  * by all non-const subclass members.
409  */
410  void detach();
411 
412  private:
413  class ByteVectorPrivate;
414  ByteVectorPrivate *d;
415  };
416 
417 }
418 
423 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
424 
425 #endif