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(char oldByte, char newByte);
187 
192  ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
193 
204  int endsWithPartialMatch(const ByteVector &pattern) const;
205 
209  ByteVector &append(const ByteVector &v);
210 
214  ByteVector &append(char c);
215 
219  ByteVector &clear();
220 
224  unsigned int size() const;
225 
231  ByteVector &resize(unsigned int size, char padding = 0);
232 
236  Iterator begin();
237 
241  ConstIterator begin() const;
242 
246  Iterator end();
247 
251  ConstIterator end() const;
252 
256  ReverseIterator rbegin();
257 
261  ConstReverseIterator rbegin() const;
262 
266  ReverseIterator rend();
267 
271  ConstReverseIterator rend() const;
272 
283  // BIC: remove
284  bool isNull() const;
285 
292  bool isEmpty() const;
293 
299  // BIC: Remove or make generic.
300  unsigned int checksum() const;
301 
312  unsigned int toUInt(bool mostSignificantByteFirst = true) const;
313 
324  unsigned int toUInt(unsigned int offset, bool mostSignificantByteFirst = true) const;
325 
337  unsigned int toUInt(unsigned int offset, unsigned int length,
338  bool mostSignificantByteFirst = true) const;
339 
349  short toShort(bool mostSignificantByteFirst = true) const;
350 
360  short toShort(unsigned int offset, bool mostSignificantByteFirst = true) const;
361 
371  unsigned short toUShort(bool mostSignificantByteFirst = true) const;
372 
382  unsigned short toUShort(unsigned int offset, bool mostSignificantByteFirst = true) const;
383 
394  long long toLongLong(bool mostSignificantByteFirst = true) const;
395 
406  long long toLongLong(unsigned int offset, bool mostSignificantByteFirst = true) const;
407 
408  /*
409  * Converts the 4 bytes at \a offset of the vector to a float as an IEEE754
410  * 32-bit little-endian floating point number.
411  */
412  float toFloat32LE(size_t offset) const;
413 
414  /*
415  * Converts the 4 bytes at \a offset of the vector to a float as an IEEE754
416  * 32-bit big-endian floating point number.
417  */
418  float toFloat32BE(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 little-endian floating point number.
423  */
424  double toFloat64LE(size_t offset) const;
425 
426  /*
427  * Converts the 8 bytes at \a offset of the vector to a double as an IEEE754
428  * 64-bit big-endian floating point number.
429  */
430  double toFloat64BE(size_t offset) const;
431 
432  /*
433  * Converts the 10 bytes at \a offset of the vector to a long double as an
434  * IEEE754 80-bit little-endian floating point number.
435  *
436  * \note This may compromise the precision depends on the size of long double.
437  */
438  long double toFloat80LE(size_t offset) const;
439 
440  /*
441  * Converts the 10 bytes at \a offset of the vector to a long double as an
442  * IEEE754 80-bit big-endian floating point number.
443  *
444  * \note This may compromise the precision depends on the size of long double.
445  */
446  long double toFloat80BE(size_t offset) const;
447 
457  static ByteVector fromUInt(unsigned int value, bool mostSignificantByteFirst = true);
458 
467  static ByteVector fromShort(short value, bool mostSignificantByteFirst = true);
468 
478  static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true);
479 
486  static ByteVector fromFloat32LE(float value);
487 
494  static ByteVector fromFloat32BE(float value);
495 
502  static ByteVector fromFloat64LE(double value);
503 
510  static ByteVector fromFloat64BE(double value);
511 
515  static ByteVector fromCString(const char *s, unsigned int length = 0xffffffff);
516 
520  const char &operator[](int index) const;
521 
525  char &operator[](int index);
526 
530  bool operator==(const ByteVector &v) const;
531 
535  bool operator!=(const ByteVector &v) const;
536 
541  bool operator==(const char *s) const;
542 
547  bool operator!=(const char *s) const;
548 
554  bool operator<(const ByteVector &v) const;
555 
559  bool operator>(const ByteVector &v) const;
560 
564  ByteVector operator+(const ByteVector &v) const;
565 
569  ByteVector &operator=(const ByteVector &v);
570 
574  ByteVector &operator=(char c);
575 
581  ByteVector &operator=(const char *data);
582 
586  void swap(ByteVector &v);
587 
597  // BIC: remove
598  static ByteVector null;
599 
603  ByteVector toHex() const;
604 
608  ByteVector toBase64() const;
609 
613  static ByteVector fromBase64(const ByteVector &);
614 
615  protected:
616  /*
617  * If this ByteVector is being shared via implicit sharing, do a deep copy
618  * of the data and separate from the shared members. This should be called
619  * by all non-const subclass members.
620  */
621  void detach();
622 
623  private:
624  class ByteVectorPrivate;
625  ByteVectorPrivate *d;
626  };
627 }
628 
633 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
634 
635 #endif
static ByteVector null
Definition: tbytevector.h:598
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)