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(unsigned int size, char value = 0);
65 
69  ByteVector(const ByteVector &v);
70 
74  ByteVector(const ByteVector &v, unsigned int offset, unsigned int length);
75 
79  ByteVector(char c);
80 
84  ByteVector(const char *data, unsigned int length);
85 
93  ByteVector(const char *data);
94 
98  virtual ~ByteVector();
99 
103  ByteVector &setData(const char *data, unsigned int length);
104 
109  ByteVector &setData(const char *data);
110 
118  char *data();
119 
123  const char *data() const;
124 
130  ByteVector mid(unsigned int index, unsigned int length = 0xffffffff) const;
131 
136  char at(unsigned int index) const;
137 
144  int find(const ByteVector &pattern, unsigned int offset = 0, int byteAlign = 1) const;
145 
152  int find(char c, unsigned int offset = 0, int byteAlign = 1) const;
153 
160  int rfind(const ByteVector &pattern, unsigned int offset = 0, int byteAlign = 1) const;
161 
169  bool containsAt(const ByteVector &pattern, unsigned int offset,
170  unsigned int patternOffset = 0, unsigned int patternLength = 0xffffffff) const;
171 
175  bool startsWith(const ByteVector &pattern) const;
176 
180  bool endsWith(const ByteVector &pattern) const;
181 
186  ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
187 
198  int endsWithPartialMatch(const ByteVector &pattern) const;
199 
203  ByteVector &append(const ByteVector &v);
204 
208  ByteVector &append(char c);
209 
213  ByteVector &clear();
214 
218  unsigned int size() const;
219 
225  ByteVector &resize(unsigned int size, char padding = 0);
226 
230  Iterator begin();
231 
235  ConstIterator begin() const;
236 
240  Iterator end();
241 
245  ConstIterator end() const;
246 
250  ReverseIterator rbegin();
251 
255  ConstReverseIterator rbegin() const;
256 
260  ReverseIterator rend();
261 
265  ConstReverseIterator rend() const;
266 
277  // BIC: remove
278  bool isNull() const;
279 
286  bool isEmpty() const;
287 
293  // BIC: Remove or make generic.
294  unsigned int checksum() const;
295 
306  unsigned int toUInt(bool mostSignificantByteFirst = true) const;
307 
318  unsigned int toUInt(unsigned int offset, bool mostSignificantByteFirst = true) const;
319 
331  unsigned int toUInt(unsigned int offset, unsigned int length,
332  bool mostSignificantByteFirst = true) const;
333 
343  short toShort(bool mostSignificantByteFirst = true) const;
344 
354  short toShort(unsigned int offset, bool mostSignificantByteFirst = true) const;
355 
365  unsigned short toUShort(bool mostSignificantByteFirst = true) const;
366 
376  unsigned short toUShort(unsigned int offset, bool mostSignificantByteFirst = true) const;
377 
388  long long toLongLong(bool mostSignificantByteFirst = true) const;
389 
400  long long toLongLong(unsigned int offset, bool mostSignificantByteFirst = true) const;
401 
402  /*
403  * Converts the 4 bytes at \a offset of the vector to a float as an IEEE754
404  * 32-bit little-endian floating point number.
405  */
406  float toFloat32LE(size_t offset) const;
407 
408  /*
409  * Converts the 4 bytes at \a offset of the vector to a float as an IEEE754
410  * 32-bit big-endian floating point number.
411  */
412  float toFloat32BE(size_t offset) const;
413 
414  /*
415  * Converts the 8 bytes at \a offset of the vector to a double as an IEEE754
416  * 64-bit little-endian floating point number.
417  */
418  double toFloat64LE(size_t offset) const;
419 
420  /*
421  * Converts the 8 bytes at \a offset of the vector to a double as an IEEE754
422  * 64-bit big-endian floating point number.
423  */
424  double toFloat64BE(size_t offset) const;
425 
426  /*
427  * Converts the 10 bytes at \a offset of the vector to a long double as an
428  * IEEE754 80-bit little-endian floating point number.
429  *
430  * \note This may compromise the precision depends on the size of long double.
431  */
432  long double toFloat80LE(size_t offset) const;
433 
434  /*
435  * Converts the 10 bytes at \a offset of the vector to a long double as an
436  * IEEE754 80-bit big-endian floating point number.
437  *
438  * \note This may compromise the precision depends on the size of long double.
439  */
440  long double toFloat80BE(size_t offset) const;
441 
451  static ByteVector fromUInt(unsigned int value, bool mostSignificantByteFirst = true);
452 
461  static ByteVector fromShort(short value, bool mostSignificantByteFirst = true);
462 
472  static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true);
473 
480  static ByteVector fromFloat32LE(float value);
481 
488  static ByteVector fromFloat32BE(float value);
489 
496  static ByteVector fromFloat64LE(double value);
497 
504  static ByteVector fromFloat64BE(double value);
505 
509  static ByteVector fromCString(const char *s, unsigned int length = 0xffffffff);
510 
514  const char &operator[](int index) const;
515 
519  char &operator[](int index);
520 
524  bool operator==(const ByteVector &v) const;
525 
529  bool operator!=(const ByteVector &v) const;
530 
535  bool operator==(const char *s) const;
536 
541  bool operator!=(const char *s) const;
542 
548  bool operator<(const ByteVector &v) const;
549 
553  bool operator>(const ByteVector &v) const;
554 
558  ByteVector operator+(const ByteVector &v) const;
559 
563  ByteVector &operator=(const ByteVector &v);
564 
568  ByteVector &operator=(char c);
569 
575  ByteVector &operator=(const char *data);
576 
580  void swap(ByteVector &v);
581 
591  // BIC: remove
592  static ByteVector null;
593 
597  ByteVector toHex() const;
598 
602  ByteVector toBase64() const;
603 
607  static ByteVector fromBase64(const ByteVector &);
608 
609  protected:
610  /*
611  * If this ByteVector is being shared via implicit sharing, do a deep copy
612  * of the data and separate from the shared members. This should be called
613  * by all non-const subclass members.
614  */
615  void detach();
616 
617  private:
618  class ByteVectorPrivate;
619  ByteVectorPrivate *d;
620  };
621 }
622 
627 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
628 
629 #endif
static ByteVector null
Definition: tbytevector.h:592
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::ByteVector &v)
A byte vector.
Definition: tbytevector.h:45
TAGLIB_EXPORT ByteVector fromUInt(unsigned int value)
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
TAGLIB_EXPORT unsigned int toUInt(const ByteVector &data)
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41