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 
93  ByteVector(const char *data);
94 
98  virtual ~ByteVector();
99 
103  ByteVector &setData(const char *data, uint length);
104 
109  ByteVector &setData(const char *data);
110 
118  char *data();
119 
123  const char *data() const;
124 
130  ByteVector mid(uint index, uint length = 0xffffffff) const;
131 
136  char at(uint index) const;
137 
144  int find(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
145 
152  int find(char c, uint offset = 0, int byteAlign = 1) const;
153 
160  int rfind(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const;
161 
169  bool containsAt(const ByteVector &pattern, uint offset, uint patternOffset = 0, uint patternLength = 0xffffffff) const;
170 
174  bool startsWith(const ByteVector &pattern) const;
175 
179  bool endsWith(const ByteVector &pattern) const;
180 
185  ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
186 
197  int endsWithPartialMatch(const ByteVector &pattern) const;
198 
202  ByteVector &append(const ByteVector &v);
203 
207  ByteVector &clear();
208 
212  uint size() const;
213 
219  ByteVector &resize(uint size, char padding = 0);
220 
224  Iterator begin();
225 
229  ConstIterator begin() const;
230 
234  Iterator end();
235 
239  ConstIterator end() const;
240 
244  ReverseIterator rbegin();
245 
249  ConstReverseIterator rbegin() const;
250 
254  ReverseIterator rend();
255 
259  ConstReverseIterator rend() const;
260 
267  bool isNull() const;
268 
275  bool isEmpty() const;
276 
282  // BIC: Remove or make generic.
283  uint checksum() const;
284 
295  uint toUInt(bool mostSignificantByteFirst = true) const;
296 
307  uint toUInt(uint offset, bool mostSignificantByteFirst = true) const;
308 
320  uint toUInt(uint offset, uint length, bool mostSignificantByteFirst = true) const;
321 
331  short toShort(bool mostSignificantByteFirst = true) const;
332 
342  short toShort(uint offset, bool mostSignificantByteFirst = true) const;
343 
353  unsigned short toUShort(bool mostSignificantByteFirst = true) const;
354 
364  unsigned short toUShort(uint offset, bool mostSignificantByteFirst = true) const;
365 
376  long long toLongLong(bool mostSignificantByteFirst = true) const;
377 
388  long long toLongLong(uint offset, bool mostSignificantByteFirst = true) const;
389 
390  /*
391  * Converts the 4 bytes at \a offset of the vector to a float as an IEEE754
392  * 32-bit little-endian floating point number.
393  */
394  float toFloat32LE(size_t offset) const;
395 
396  /*
397  * Converts the 4 bytes at \a offset of the vector to a float as an IEEE754
398  * 32-bit big-endian floating point number.
399  */
400  float toFloat32BE(size_t offset) const;
401 
402  /*
403  * Converts the 8 bytes at \a offset of the vector to a double as an IEEE754
404  * 64-bit little-endian floating point number.
405  */
406  double toFloat64LE(size_t offset) const;
407 
408  /*
409  * Converts the 8 bytes at \a offset of the vector to a double as an IEEE754
410  * 64-bit big-endian floating point number.
411  */
412  double toFloat64BE(size_t offset) const;
413 
414  /*
415  * Converts the 10 bytes at \a offset of the vector to a long double as an
416  * IEEE754 80-bit little-endian floating point number.
417  *
418  * \note This may compromise the precision depends on the size of long double.
419  */
420  long double toFloat80LE(size_t offset) const;
421 
422  /*
423  * Converts the 10 bytes at \a offset of the vector to a long double as an
424  * IEEE754 80-bit big-endian floating point number.
425  *
426  * \note This may compromise the precision depends on the size of long double.
427  */
428  long double toFloat80BE(size_t offset) const;
429 
439  static ByteVector fromUInt(uint value, bool mostSignificantByteFirst = true);
440 
449  static ByteVector fromShort(short value, bool mostSignificantByteFirst = true);
450 
460  static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true);
461 
468  static ByteVector fromFloat32LE(float value);
469 
476  static ByteVector fromFloat32BE(float value);
477 
484  static ByteVector fromFloat64LE(double value);
485 
492  static ByteVector fromFloat64BE(double value);
493 
497  static ByteVector fromCString(const char *s, uint length = 0xffffffff);
498 
502  const char &operator[](int index) const;
503 
507  char &operator[](int index);
508 
512  bool operator==(const ByteVector &v) const;
513 
517  bool operator!=(const ByteVector &v) const;
518 
523  bool operator==(const char *s) const;
524 
529  bool operator!=(const char *s) const;
530 
536  bool operator<(const ByteVector &v) const;
537 
541  bool operator>(const ByteVector &v) const;
542 
546  ByteVector operator+(const ByteVector &v) const;
547 
551  ByteVector &operator=(const ByteVector &v);
552 
556  ByteVector &operator=(char c);
557 
563  ByteVector &operator=(const char *data);
564 
569  static ByteVector null;
570 
574  ByteVector toHex() const;
575 
576  protected:
577  /*
578  * If this ByteVector is being shared via implicit sharing, do a deep copy
579  * of the data and separate from the shared members. This should be called
580  * by all non-const subclass members.
581  */
582  void detach();
583 
584  private:
585  class ByteVectorPrivate;
586  ByteVectorPrivate *d;
587  };
588 }
589 
594 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
595 
596 #endif
static ByteVector null
Definition: tbytevector.h:569
unsigned int uint
Definition: taglib.h:66
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::ByteVector &v)
A byte vector.
Definition: tbytevector.h:45
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
TAGLIB_EXPORT uint toUInt(const ByteVector &data)
TAGLIB_EXPORT ByteVector fromUInt(uint value)
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41