diff options
author | Mike Buland <eichlan@xagasoft.com> | 2023-08-09 13:00:19 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2023-08-09 13:00:19 -0700 |
commit | 9fc845c1746a83afc4e847895913851576945000 (patch) | |
tree | ab2071248b8ed1fa6660e78500bb2deaddc9741b | |
parent | c7e1277ecaf40c6d8ee945418a306f5b15189b97 (diff) | |
download | libbu++-9fc845c1746a83afc4e847895913851576945000.tar.gz libbu++-9fc845c1746a83afc4e847895913851576945000.tar.bz2 libbu++-9fc845c1746a83afc4e847895913851576945000.tar.xz libbu++-9fc845c1746a83afc4e847895913851576945000.zip |
Added a temporory String -> Blob constructor.
Just to ease the transition.
-rw-r--r-- | src/unstable/blob.cpp | 27 | ||||
-rw-r--r-- | src/unstable/blob.h | 5 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp index d343963..bf8cb5a 100644 --- a/src/unstable/blob.cpp +++ b/src/unstable/blob.cpp | |||
@@ -10,6 +10,9 @@ | |||
10 | #include "bu/exceptioninvaliditerator.h" | 10 | #include "bu/exceptioninvaliditerator.h" |
11 | #include "bu/exceptionindexoutofbounds.h" | 11 | #include "bu/exceptionindexoutofbounds.h" |
12 | 12 | ||
13 | // Temporary | ||
14 | #include "bu/string.h" | ||
15 | |||
13 | #include <string.h> | 16 | #include <string.h> |
14 | 17 | ||
15 | Bu::Blob::Blob() : | 18 | Bu::Blob::Blob() : |
@@ -97,6 +100,14 @@ Bu::Blob::Blob( const Bu::Blob::const_iterator &iStart, | |||
97 | pData[iSize] = 0; | 100 | pData[iSize] = 0; |
98 | } | 101 | } |
99 | 102 | ||
103 | Bu::Blob::Blob( const Bu::String &rSrc ) : | ||
104 | pData( 0 ), | ||
105 | iSize( rSrc.getSize() ) | ||
106 | { | ||
107 | pData = new char[rSrc.getSize()+1]; | ||
108 | memcpy( pData, rSrc.getStr(), iSize+1 ); | ||
109 | } | ||
110 | |||
100 | Bu::Blob::~Blob() | 111 | Bu::Blob::~Blob() |
101 | { | 112 | { |
102 | delete[] pData; | 113 | delete[] pData; |
@@ -117,6 +128,15 @@ int32_t Bu::Blob::getSize() const | |||
117 | return iSize; | 128 | return iSize; |
118 | } | 129 | } |
119 | 130 | ||
131 | void Bu::Blob::setData( const char *pSrc, int32_t iSize ) | ||
132 | { | ||
133 | delete[] pData; | ||
134 | pData = new char[iSize+1]; | ||
135 | memset( pData, iSize, 1 ); | ||
136 | this->iSize = iSize; | ||
137 | memcpy( pData, pSrc, iSize ); | ||
138 | } | ||
139 | |||
120 | char *Bu::Blob::getData() const | 140 | char *Bu::Blob::getData() const |
121 | { | 141 | { |
122 | return pData; | 142 | return pData; |
@@ -817,6 +837,13 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, const Bu::Blob &b ) | |||
817 | return rOut; | 837 | return rOut; |
818 | } | 838 | } |
819 | 839 | ||
840 | Bu::Formatter &Bu::operator>>( Bu::Formatter &fIn, Bu::Blob &b ) | ||
841 | { | ||
842 | Bu::String sTmp = fIn.readToken(); | ||
843 | b.setData( sTmp.getStr(), sTmp.getSize() ); | ||
844 | return fIn; | ||
845 | } | ||
846 | |||
820 | Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, const Bu::Blob &b ) | 847 | Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, const Bu::Blob &b ) |
821 | { | 848 | { |
822 | int32_t iSize = b.getSize(); | 849 | int32_t iSize = b.getSize(); |
diff --git a/src/unstable/blob.h b/src/unstable/blob.h index 2866ab2..2a665ad 100644 --- a/src/unstable/blob.h +++ b/src/unstable/blob.h | |||
@@ -46,10 +46,14 @@ namespace Bu | |||
46 | Blob( int32_t iSize ); | 46 | Blob( int32_t iSize ); |
47 | Blob( const const_iterator &iStart ); | 47 | Blob( const const_iterator &iStart ); |
48 | Blob( const const_iterator &iStart, const const_iterator &iEnd ); | 48 | Blob( const const_iterator &iStart, const const_iterator &iEnd ); |
49 | |||
50 | // Obviously temporary | ||
51 | Blob( const Bu::String &rSrc ); | ||
49 | virtual ~Blob(); | 52 | virtual ~Blob(); |
50 | 53 | ||
51 | void setSize( int32_t iSize ); | 54 | void setSize( int32_t iSize ); |
52 | int32_t getSize() const; | 55 | int32_t getSize() const; |
56 | void setData( const char *pSrc, int32_t iSize ); | ||
53 | char *getData() const; | 57 | char *getData() const; |
54 | char *c_str() const; | 58 | char *c_str() const; |
55 | 59 | ||
@@ -184,6 +188,7 @@ namespace Bu | |||
184 | 188 | ||
185 | class Formatter; | 189 | class Formatter; |
186 | Formatter &operator<<( Formatter &rOut, const Blob &b ); | 190 | Formatter &operator<<( Formatter &rOut, const Blob &b ); |
191 | Formatter &operator>>( Formatter &fIn, Blob &b ); | ||
187 | } | 192 | } |
188 | 193 | ||
189 | #endif | 194 | #endif |