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  typedef std::vector<char>::reverse_iterator ReverseIterator;
52  typedef std::vector<char>::const_reverse_iterator ConstReverseIterator;
53 #endif
54 
58  ByteVector();
59 
64  ByteVector(uint size, char value = 0);
65 
69  ByteVector(const ByteVector &v);
70 
74  ByteVector(const ByteVector &v, uint offset, uint length);
75 
79  ByteVector(char c);
80 
84  ByteVector(const char *data, uint length);
85 
92  ByteVector(const char *data);
93 
97  virtual ~ByteVector();
98 
102  ByteVector &setData(const char *data, uint length);
103 
108  ByteVector &setData(const char *data);
109 
117  char *data();
118 
122  const char *data() const;
123 
129  ByteVector mid(uint index, uint length = 0xffffffff) const;
130 
135  char at(uint index) const;
136 
143  int find(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
144 
151  int find(char c, uint offset = 0, int byteAlign = 1) const;
152 
159  int rfind(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
160 
168  bool containsAt(const ByteVector &pattern, uint offset, uint patternOffset = 0, uint patternLength = 0xffffffff) const;
169 
173  bool startsWith(const ByteVector &pattern) const;
174 
178  bool endsWith(const ByteVector &pattern) const;
179 
184  ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
185 
196  int endsWithPartialMatch(const ByteVector &pattern) const;
197 
201  ByteVector &append(const ByteVector &v);
202 
206  ByteVector &clear();
207 
211  uint size() const;
212 
218  ByteVector &resize(uint size, char padding = 0);
219 
223  Iterator begin();
224 
228  ConstIterator begin() const;
229 
233  Iterator end();
234 
238  ConstIterator end() const;
239 
243  ReverseIterator rbegin();
244 
248  ConstReverseIterator rbegin() const;
249 
253  ReverseIterator rend();
254 
258  ConstReverseIterator rend() const;
259 
266  bool isNull() const;
267 
274  bool isEmpty() const;
275 
279  uint checksum() const;
280 
291  uint toUInt(bool mostSignificantByteFirst = true) const;
292 
303  uint toUInt(uint offset, bool mostSignificantByteFirst = true) const;
304 
316  uint toUInt(uint offset, uint length, bool mostSignificantByteFirst = true) const;
317 
327  short toShort(bool mostSignificantByteFirst = true) const;
328 
338  short toShort(uint offset, bool mostSignificantByteFirst = true) const;
339 
349  unsigned short toUShort(bool mostSignificantByteFirst = true) const;
350 
360  unsigned short toUShort(uint offset, bool mostSignificantByteFirst = true) const;
361 
372  long long toLongLong(bool mostSignificantByteFirst = true) const;
373 
384  long long toLongLong(uint offset, bool mostSignificantByteFirst = true) const;
385 
395  static ByteVector fromUInt(uint value, bool mostSignificantByteFirst = true);
396 
405  static ByteVector fromShort(short value, bool mostSignificantByteFirst = true);
406 
416  static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true);
417 
421  static ByteVector fromCString(const char *s, uint length = 0xffffffff);
422 
426  const char &operator[](int index) const;
427 
431  char &operator[](int index);
432 
436  bool operator==(const ByteVector &v) const;
437 
441  bool operator!=(const ByteVector &v) const;
442 
447  bool operator==(const char *s) const;
448 
453  bool operator!=(const char *s) const;
454 
460  bool operator<(const ByteVector &v) const;
461 
465  bool operator>(const ByteVector &v) const;
466 
470  ByteVector operator+(const ByteVector &v) const;
471 
475  ByteVector &operator=(const ByteVector &v);
476 
480  ByteVector &operator=(char c);
481 
485  ByteVector &operator=(const char *data);
486 
491  static ByteVector null;
492 
496  ByteVector toHex() const;
497 
498  protected:
499  /*
500  * If this ByteVector is being shared via implicit sharing, do a deep copy
501  * of the data and separate from the shared members. This should be called
502  * by all non-const subclass members.
503  */
504  void detach();
505 
506  private:
507  class ByteVectorPrivate;
508  ByteVectorPrivate *d;
509  };
510 }
511 
516 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
517 
518 #endif