1 #include "api/internal/io/ByteArray_p.h"
2 using namespace BamTools;
3 using namespace BamTools::Internal;
5 #include <iostream> // debug
11 // --------------------------
12 // ByteArray implementation
13 // --------------------------
15 ByteArray::ByteArray(void)
19 ByteArray::ByteArray(const string& value)
20 : m_data(value.begin(), value.end())
23 ByteArray::ByteArray(const vector<char>& value)
27 ByteArray::ByteArray(const char* value, size_t n) {
28 const string s(value, n);
29 m_data.assign(s.begin(), s.end());
32 ByteArray::ByteArray(const ByteArray& other)
33 : m_data(other.m_data)
36 ByteArray::~ByteArray(void) { }
38 ByteArray& ByteArray::operator=(const ByteArray& other) {
39 m_data = other.m_data;
43 void ByteArray::Clear(void) {
47 const char* ByteArray::ConstData(void) const {
51 char* ByteArray::Data(void) {
55 const char& ByteArray::operator[](size_t i) const {
59 char& ByteArray::operator[](size_t i) {
63 size_t ByteArray::IndexOf(const char c, const size_t from, const size_t to) const {
64 const size_t size = ( (to == 0 ) ? m_data.size() : to );
65 for ( size_t i = from; i < size; ++i ) {
66 if ( m_data.at(i) == c )
72 ByteArray& ByteArray::Remove(size_t from, size_t n) {
74 // if 'from' outside range, just return
75 const size_t originalSize = m_data.size();
76 if ( from >= originalSize )
79 // if asked to clip from 'from' to end (or beyond), simply resize
80 if ( from + n >= originalSize )
83 // otherwise, shift data & resize
85 memmove( &m_data[from], &m_data[from+n], (originalSize-from-n) );
86 Resize(originalSize - n);
89 // return reference to modified byte array
93 void ByteArray::Resize(size_t n) {
97 size_t ByteArray::Size(void) const {
101 void ByteArray::Squeeze(void) {
102 vector<char> t(m_data);