TagLib  1.13
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
35namespace 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
59
64 ByteVector(unsigned int size, char value = 0);
65
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
210
215
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
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
565
570
575
581 ByteVector &operator=(const char *data);
582
586 void swap(ByteVector &v);
587
597 // BIC: remove
599
604
609
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
633TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v);
634
635#endif
A byte vector.
Definition: tbytevector.h:46
ReverseIterator rbegin()
long double toFloat80BE(size_t offset) const
int endsWithPartialMatch(const ByteVector &pattern) const
char at(unsigned int index) const
static ByteVector fromCString(const char *s, unsigned int length=0xffffffff)
static ByteVector fromShort(short value, bool mostSignificantByteFirst=true)
ReverseIterator rend()
int find(char c, unsigned int offset=0, int byteAlign=1) const
long long toLongLong(unsigned int offset, bool mostSignificantByteFirst=true) const
unsigned int checksum() const
static ByteVector fromBase64(const ByteVector &)
ByteVector & append(char c)
ConstReverseIterator rbegin() const
bool operator!=(const char *s) const
unsigned short toUShort(bool mostSignificantByteFirst=true) const
ByteVector & setData(const char *data, unsigned int length)
ByteVector(unsigned int size, char value=0)
int rfind(const ByteVector &pattern, unsigned int offset=0, int byteAlign=1) const
ByteVector & clear()
ConstIterator end() const
virtual ~ByteVector()
ByteVector & replace(const ByteVector &pattern, const ByteVector &with)
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::ByteVector &v)
char & operator[](int index)
ByteVector toHex() const
long double toFloat80LE(size_t offset) const
bool operator!=(const ByteVector &v) const
static TAGLIB_DEPRECATED ByteVector null
Definition: tbytevector.h:598
double toFloat64LE(size_t offset) const
int find(const ByteVector &pattern, unsigned int offset=0, int byteAlign=1) const
bool isEmpty() const
float toFloat32LE(size_t offset) const
static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst=true)
static ByteVector fromFloat64LE(double value)
short toShort(unsigned int offset, bool mostSignificantByteFirst=true) const
ByteVector(const ByteVector &v)
bool endsWith(const ByteVector &pattern) const
ByteVector toBase64() const
ConstIterator begin() const
static ByteVector fromFloat32LE(float value)
void swap(ByteVector &v)
ConstReverseIterator rend() const
ByteVector & operator=(const char *data)
bool containsAt(const ByteVector &pattern, unsigned int offset, unsigned int patternOffset=0, unsigned int patternLength=0xffffffff) const
TAGLIB_DEPRECATED bool isNull() const
static ByteVector fromUInt(unsigned int value, bool mostSignificantByteFirst=true)
ByteVector & resize(unsigned int size, char padding=0)
float toFloat32BE(size_t offset) const
ByteVector & replace(char oldByte, char newByte)
bool operator==(const char *s) const
bool operator<(const ByteVector &v) const
ByteVector(const char *data)
ByteVector & append(const ByteVector &v)
ByteVector & setData(const char *data)
bool startsWith(const ByteVector &pattern) const
static ByteVector fromFloat64BE(double value)
unsigned int toUInt(bool mostSignificantByteFirst=true) const
unsigned int size() const
ByteVector & operator=(const ByteVector &v)
double toFloat64BE(size_t offset) const
unsigned int toUInt(unsigned int offset, bool mostSignificantByteFirst=true) const
ByteVector operator+(const ByteVector &v) const
ByteVector & operator=(char c)
const char * data() const
bool operator==(const ByteVector &v) const
static ByteVector fromFloat32BE(float value)
ByteVector mid(unsigned int index, unsigned int length=0xffffffff) const
long long toLongLong(bool mostSignificantByteFirst=true) const
bool operator>(const ByteVector &v) const
unsigned int toUInt(unsigned int offset, unsigned int length, bool mostSignificantByteFirst=true) const
const char & operator[](int index) const
ByteVector(const char *data, unsigned int length)
ByteVector(const ByteVector &v, unsigned int offset, unsigned int length)
unsigned short toUShort(unsigned int offset, bool mostSignificantByteFirst=true) const
short toShort(bool mostSignificantByteFirst=true) const
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41
#define TAGLIB_DEPRECATED
Definition: taglib.h:54
#define TAGLIB_EXPORT
Definition: taglib_export.h:40