aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/blob.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2023-08-09 13:00:19 -0700
committerMike Buland <eichlan@xagasoft.com>2023-08-09 13:00:19 -0700
commit9fc845c1746a83afc4e847895913851576945000 (patch)
treeab2071248b8ed1fa6660e78500bb2deaddc9741b /src/unstable/blob.cpp
parentc7e1277ecaf40c6d8ee945418a306f5b15189b97 (diff)
downloadlibbu++-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.
Diffstat (limited to 'src/unstable/blob.cpp')
-rw-r--r--src/unstable/blob.cpp27
1 files changed, 27 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
15Bu::Blob::Blob() : 18Bu::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
103Bu::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
100Bu::Blob::~Blob() 111Bu::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
131void 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
120char *Bu::Blob::getData() const 140char *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
840Bu::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
820Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, const Bu::Blob &b ) 847Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, const Bu::Blob &b )
821{ 848{
822 int32_t iSize = b.getSize(); 849 int32_t iSize = b.getSize();