tbytevector.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef TAGLIB_BYTEVECTOR_H
00027 #define TAGLIB_BYTEVECTOR_H
00028
00029 #include "taglib.h"
00030 #include "taglib_export.h"
00031
00032 #include <vector>
00033 #include <iostream>
00034
00035 namespace TagLib {
00036
00038
00045 class TAGLIB_EXPORT ByteVector
00046 {
00047 public:
00048 #ifndef DO_NOT_DOCUMENT
00049 typedef std::vector<char>::iterator Iterator;
00050 typedef std::vector<char>::const_iterator ConstIterator;
00051 typedef std::vector<char>::reverse_iterator ReverseIterator;
00052 typedef std::vector<char>::const_reverse_iterator ConstReverseIterator;
00053 #endif
00054
00058 ByteVector();
00059
00064 ByteVector(unsigned int size, char value = 0);
00065
00069 ByteVector(const ByteVector &v);
00070
00074 ByteVector(const ByteVector &v, unsigned int offset, unsigned int length);
00075
00079 ByteVector(char c);
00080
00084 ByteVector(const char *data, unsigned int length);
00085
00093 ByteVector(const char *data);
00094
00098 virtual ~ByteVector();
00099
00103 ByteVector &setData(const char *data, unsigned int length);
00104
00109 ByteVector &setData(const char *data);
00110
00118 char *data();
00119
00123 const char *data() const;
00124
00130 ByteVector mid(unsigned int index, unsigned int length = 0xffffffff) const;
00131
00136 char at(unsigned int index) const;
00137
00144 int find(const ByteVector &pattern, unsigned int offset = 0, int byteAlign = 1) const;
00145
00152 int find(char c, unsigned int offset = 0, int byteAlign = 1) const;
00153
00160 int rfind(const ByteVector &pattern, unsigned int offset = 0, int byteAlign = 1) const;
00161
00169 bool containsAt(const ByteVector &pattern, unsigned int offset,
00170 unsigned int patternOffset = 0, unsigned int patternLength = 0xffffffff) const;
00171
00175 bool startsWith(const ByteVector &pattern) const;
00176
00180 bool endsWith(const ByteVector &pattern) const;
00181
00186 ByteVector &replace(char oldByte, char newByte);
00187
00192 ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
00193
00204 int endsWithPartialMatch(const ByteVector &pattern) const;
00205
00209 ByteVector &append(const ByteVector &v);
00210
00214 ByteVector &append(char c);
00215
00219 ByteVector &clear();
00220
00224 unsigned int size() const;
00225
00231 ByteVector &resize(unsigned int size, char padding = 0);
00232
00236 Iterator begin();
00237
00241 ConstIterator begin() const;
00242
00246 Iterator end();
00247
00251 ConstIterator end() const;
00252
00256 ReverseIterator rbegin();
00257
00261 ConstReverseIterator rbegin() const;
00262
00266 ReverseIterator rend();
00267
00271 ConstReverseIterator rend() const;
00272
00283
00284 bool isNull() const;
00285
00292 bool isEmpty() const;
00293
00299
00300 unsigned int checksum() const;
00301
00312 unsigned int toUInt(bool mostSignificantByteFirst = true) const;
00313
00324 unsigned int toUInt(unsigned int offset, bool mostSignificantByteFirst = true) const;
00325
00337 unsigned int toUInt(unsigned int offset, unsigned int length,
00338 bool mostSignificantByteFirst = true) const;
00339
00349 short toShort(bool mostSignificantByteFirst = true) const;
00350
00360 short toShort(unsigned int offset, bool mostSignificantByteFirst = true) const;
00361
00371 unsigned short toUShort(bool mostSignificantByteFirst = true) const;
00372
00382 unsigned short toUShort(unsigned int offset, bool mostSignificantByteFirst = true) const;
00383
00394 long long toLongLong(bool mostSignificantByteFirst = true) const;
00395
00406 long long toLongLong(unsigned int offset, bool mostSignificantByteFirst = true) const;
00407
00408
00409
00410
00411
00412 float toFloat32LE(size_t offset) const;
00413
00414
00415
00416
00417
00418 float toFloat32BE(size_t offset) const;
00419
00420
00421
00422
00423
00424 double toFloat64LE(size_t offset) const;
00425
00426
00427
00428
00429
00430 double toFloat64BE(size_t offset) const;
00431
00432
00433
00434
00435
00436
00437
00438 long double toFloat80LE(size_t offset) const;
00439
00440
00441
00442
00443
00444
00445
00446 long double toFloat80BE(size_t offset) const;
00447
00457 static ByteVector fromUInt(unsigned int value, bool mostSignificantByteFirst = true);
00458
00467 static ByteVector fromShort(short value, bool mostSignificantByteFirst = true);
00468
00478 static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true);
00479
00486 static ByteVector fromFloat32LE(float value);
00487
00494 static ByteVector fromFloat32BE(float value);
00495
00502 static ByteVector fromFloat64LE(double value);
00503
00510 static ByteVector fromFloat64BE(double value);
00511
00515 static ByteVector fromCString(const char *s, unsigned int length = 0xffffffff);
00516
00520 const char &operator[](int index) const;
00521
00525 char &operator[](int index);
00526
00530 bool operator==(const ByteVector &v) const;
00531
00535 bool operator!=(const ByteVector &v) const;
00536
00541 bool operator==(const char *s) const;
00542
00547 bool operator!=(const char *s) const;
00548
00554 bool operator<(const ByteVector &v) const;
00555
00559 bool operator>(const ByteVector &v) const;
00560
00564 ByteVector operator+(const ByteVector &v) const;
00565
00569 ByteVector &operator=(const ByteVector &v);
00570
00574 ByteVector &operator=(char c);
00575
00581 ByteVector &operator=(const char *data);
00582
00586 void swap(ByteVector &v);
00587
00597
00598 static ByteVector null;
00599
00603 ByteVector toHex() const;
00604
00608 ByteVector toBase64() const;
00609
00613 static ByteVector fromBase64(const ByteVector &);
00614
00615 protected:
00616
00617
00618
00619
00620
00621 void detach();
00622
00623 private:
00624 class ByteVectorPrivate;
00625 ByteVectorPrivate *d;
00626 };
00627 }
00628
00633 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
00634
00635 #endif