diff options
-rw-r--r-- | src/stable/archive.cpp | 84 | ||||
-rw-r--r-- | src/stable/archive.h | 46 | ||||
-rw-r--r-- | src/stable/archivebinary.cpp | 190 | ||||
-rw-r--r-- | src/stable/archivebinary.h | 40 | ||||
-rw-r--r-- | src/stable/crypt.cpp | 4 | ||||
-rw-r--r-- | src/stable/membuf.cpp | 5 | ||||
-rw-r--r-- | src/stable/membuf.h | 2 | ||||
-rw-r--r-- | src/stable/string.cpp | 12 | ||||
-rw-r--r-- | src/tests/archivetags.cpp | 73 | ||||
-rw-r--r-- | src/unstable/archivestream.cpp | 127 | ||||
-rw-r--r-- | src/unstable/archivestream.h | 49 | ||||
-rw-r--r-- | src/unstable/blob.cpp | 20 | ||||
-rw-r--r-- | src/unstable/blob.h | 3 | ||||
-rw-r--r-- | src/unstable/uuid.cpp | 34 | ||||
-rw-r--r-- | src/unstable/uuid.h | 15 |
15 files changed, 463 insertions, 241 deletions
diff --git a/src/stable/archive.cpp b/src/stable/archive.cpp index df9b1ff..829e7eb 100644 --- a/src/stable/archive.cpp +++ b/src/stable/archive.cpp | |||
@@ -17,181 +17,205 @@ Bu::Archive::~Archive() | |||
17 | 17 | ||
18 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, bool p) | 18 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, bool p) |
19 | { | 19 | { |
20 | ar.write( &p, sizeof(p) ); | 20 | ar.write( p ); |
21 | return ar; | 21 | return ar; |
22 | } | 22 | } |
23 | 23 | ||
24 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, char p) | 24 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, char p) |
25 | { | 25 | { |
26 | ar.write( &p, sizeof(p) ); | 26 | ar.write( p ); |
27 | return ar; | 27 | return ar; |
28 | } | 28 | } |
29 | 29 | ||
30 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed char p) | 30 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed char p) |
31 | { | 31 | { |
32 | ar.write( &p, sizeof(p) ); | 32 | ar.write( p ); |
33 | return ar; | 33 | return ar; |
34 | } | 34 | } |
35 | 35 | ||
36 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned char p) | 36 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned char p) |
37 | { | 37 | { |
38 | ar.write( &p, sizeof(p) ); | 38 | ar.write( p ); |
39 | return ar; | 39 | return ar; |
40 | } | 40 | } |
41 | 41 | ||
42 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed short p) | 42 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed short p) |
43 | { | 43 | { |
44 | ar.write( &p, sizeof(p) ); | 44 | ar.write( p ); |
45 | return ar; | 45 | return ar; |
46 | } | 46 | } |
47 | 47 | ||
48 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned short p) | 48 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned short p) |
49 | { | 49 | { |
50 | ar.write( &p, sizeof(p) ); | 50 | ar.write( p ); |
51 | return ar; | 51 | return ar; |
52 | } | 52 | } |
53 | 53 | ||
54 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed int p) | 54 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed int p) |
55 | { | 55 | { |
56 | ar.write( &p, sizeof(p) ); | 56 | ar.write( p ); |
57 | return ar; | 57 | return ar; |
58 | } | 58 | } |
59 | 59 | ||
60 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned int p) | 60 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned int p) |
61 | { | 61 | { |
62 | ar.write( &p, sizeof(p) ); | 62 | ar.write( p ); |
63 | return ar; | 63 | return ar; |
64 | } | 64 | } |
65 | 65 | ||
66 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long p) | 66 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long p) |
67 | { | 67 | { |
68 | ar.write( &p, sizeof(p) ); | 68 | ar.write( p ); |
69 | return ar; | 69 | return ar; |
70 | } | 70 | } |
71 | 71 | ||
72 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long p) | 72 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long p) |
73 | { | 73 | { |
74 | ar.write( &p, sizeof(p) ); | 74 | ar.write( p ); |
75 | return ar; | 75 | return ar; |
76 | } | 76 | } |
77 | 77 | ||
78 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long long p) | 78 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long long p) |
79 | { | 79 | { |
80 | ar.write( &p, sizeof(p) ); | 80 | ar.write( p ); |
81 | return ar; | 81 | return ar; |
82 | } | 82 | } |
83 | 83 | ||
84 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long long p) | 84 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long long p) |
85 | { | 85 | { |
86 | ar.write( &p, sizeof(p) ); | 86 | ar.write( p ); |
87 | return ar; | 87 | return ar; |
88 | } | 88 | } |
89 | 89 | ||
90 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, float p) | 90 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, float p) |
91 | { | 91 | { |
92 | ar.write( &p, sizeof(p) ); | 92 | ar.write( p ); |
93 | return ar; | 93 | return ar; |
94 | } | 94 | } |
95 | 95 | ||
96 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, double p) | 96 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, double p) |
97 | { | 97 | { |
98 | ar.write( &p, sizeof(p) ); | 98 | ar.write( p ); |
99 | return ar; | 99 | return ar; |
100 | } | 100 | } |
101 | 101 | ||
102 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, long double p) | 102 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, long double p) |
103 | { | 103 | { |
104 | ar.write( &p, sizeof(p) ); | 104 | ar.write( p ); |
105 | return ar; | ||
106 | } | ||
107 | |||
108 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Blob &p) | ||
109 | { | ||
110 | ar.write( p ); | ||
111 | return ar; | ||
112 | } | ||
113 | |||
114 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Text &p) | ||
115 | { | ||
116 | ar.write( p ); | ||
105 | return ar; | 117 | return ar; |
106 | } | 118 | } |
107 | 119 | ||
108 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, bool &p) | 120 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, bool &p) |
109 | { | 121 | { |
110 | ar.read( &p, sizeof(p) ); | 122 | ar.read( p ); |
111 | return ar; | 123 | return ar; |
112 | } | 124 | } |
113 | 125 | ||
114 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, char &p) | 126 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, char &p) |
115 | { | 127 | { |
116 | ar.read( &p, sizeof(p) ); | 128 | ar.read( p ); |
117 | return ar; | 129 | return ar; |
118 | } | 130 | } |
119 | 131 | ||
120 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed char &p) | 132 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed char &p) |
121 | { | 133 | { |
122 | ar.read( &p, sizeof(p) ); | 134 | ar.read( p ); |
123 | return ar; | 135 | return ar; |
124 | } | 136 | } |
125 | 137 | ||
126 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned char &p) | 138 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned char &p) |
127 | { | 139 | { |
128 | ar.read( &p, sizeof(p) ); | 140 | ar.read( p ); |
129 | return ar; | 141 | return ar; |
130 | } | 142 | } |
131 | 143 | ||
132 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed short &p) | 144 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed short &p) |
133 | { | 145 | { |
134 | ar.read( &p, sizeof(p) ); | 146 | ar.read( p ); |
135 | return ar; | 147 | return ar; |
136 | } | 148 | } |
137 | 149 | ||
138 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned short &p) | 150 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned short &p) |
139 | { | 151 | { |
140 | ar.read( &p, sizeof(p) ); | 152 | ar.read( p ); |
141 | return ar; | 153 | return ar; |
142 | } | 154 | } |
143 | 155 | ||
144 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed int &p) | 156 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed int &p) |
145 | { | 157 | { |
146 | ar.read( &p, sizeof(p) ); | 158 | ar.read( p ); |
147 | return ar; | 159 | return ar; |
148 | } | 160 | } |
149 | 161 | ||
150 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned int &p) | 162 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned int &p) |
151 | { | 163 | { |
152 | ar.read( &p, sizeof(p) ); | 164 | ar.read( p ); |
153 | return ar; | 165 | return ar; |
154 | } | 166 | } |
155 | 167 | ||
156 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long &p) | 168 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long &p) |
157 | { | 169 | { |
158 | ar.read( &p, sizeof(p) ); | 170 | ar.read( p ); |
159 | return ar; | 171 | return ar; |
160 | } | 172 | } |
161 | 173 | ||
162 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long &p) | 174 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long &p) |
163 | { | 175 | { |
164 | ar.read( &p, sizeof(p) ); | 176 | ar.read( p ); |
165 | return ar; | 177 | return ar; |
166 | } | 178 | } |
167 | 179 | ||
168 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long long &p) | 180 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long long &p) |
169 | { | 181 | { |
170 | ar.read( &p, sizeof(p) ); | 182 | ar.read( p ); |
171 | return ar; | 183 | return ar; |
172 | } | 184 | } |
173 | 185 | ||
174 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long long &p) | 186 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long long &p) |
175 | { | 187 | { |
176 | ar.read( &p, sizeof(p) ); | 188 | ar.read( p ); |
177 | return ar; | 189 | return ar; |
178 | } | 190 | } |
179 | 191 | ||
180 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, float &p) | 192 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, float &p) |
181 | { | 193 | { |
182 | ar.read( &p, sizeof(p) ); | 194 | ar.read( p ); |
183 | return ar; | 195 | return ar; |
184 | } | 196 | } |
185 | 197 | ||
186 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, double &p) | 198 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, double &p) |
187 | { | 199 | { |
188 | ar.read( &p, sizeof(p) ); | 200 | ar.read( p ); |
189 | return ar; | 201 | return ar; |
190 | } | 202 | } |
191 | 203 | ||
192 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, long double &p) | 204 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, long double &p) |
193 | { | 205 | { |
194 | ar.read( &p, sizeof(p) ); | 206 | ar.read( p ); |
207 | return ar; | ||
208 | } | ||
209 | |||
210 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Blob &p) | ||
211 | { | ||
212 | ar.read( p ); | ||
213 | return ar; | ||
214 | } | ||
215 | |||
216 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Text &p) | ||
217 | { | ||
218 | ar.read( p ); | ||
195 | return ar; | 219 | return ar; |
196 | } | 220 | } |
197 | 221 | ||
diff --git a/src/stable/archive.h b/src/stable/archive.h index 45d9af6..2cd340c 100644 --- a/src/stable/archive.h +++ b/src/stable/archive.h | |||
@@ -16,6 +16,8 @@ | |||
16 | 16 | ||
17 | namespace Bu | 17 | namespace Bu |
18 | { | 18 | { |
19 | class Text; | ||
20 | |||
19 | class Archive | 21 | class Archive |
20 | { | 22 | { |
21 | public: | 23 | public: |
@@ -29,10 +31,46 @@ namespace Bu | |||
29 | }; | 31 | }; |
30 | 32 | ||
31 | virtual void close()=0; | 33 | virtual void close()=0; |
32 | virtual void write( const void *pData, size_t iLength )=0; | 34 | // virtual void write( const void *pData, size_t iLength )=0; |
33 | virtual void read( void *pData, size_t iLength )=0; | 35 | // virtual void read( void *pData, size_t iLength )=0; |
34 | virtual bool isLoading()=0; | 36 | virtual bool isLoading()=0; |
35 | 37 | ||
38 | virtual void write( bool rData )=0; | ||
39 | virtual void write( unsigned char rData )=0; | ||
40 | virtual void write( char rData )=0; | ||
41 | virtual void write( signed char rData )=0; | ||
42 | virtual void write( unsigned short rData )=0; | ||
43 | virtual void write( signed short rData )=0; | ||
44 | virtual void write( unsigned int rData )=0; | ||
45 | virtual void write( signed int rData )=0; | ||
46 | virtual void write( unsigned long rData )=0; | ||
47 | virtual void write( signed long rData )=0; | ||
48 | virtual void write( unsigned long long rData )=0; | ||
49 | virtual void write( signed long long rData )=0; | ||
50 | virtual void write( float rData )=0; | ||
51 | virtual void write( double rData )=0; | ||
52 | virtual void write( long double rData )=0; | ||
53 | virtual void write( const Bu::Blob &rData )=0; | ||
54 | virtual void write( const Bu::Text &rData )=0; | ||
55 | |||
56 | virtual void read( bool &rData )=0; | ||
57 | virtual void read( unsigned char &rData )=0; | ||
58 | virtual void read( char &rData )=0; | ||
59 | virtual void read( signed char &rData )=0; | ||
60 | virtual void read( unsigned short &rData )=0; | ||
61 | virtual void read( signed short &rData )=0; | ||
62 | virtual void read( unsigned int &rData )=0; | ||
63 | virtual void read( signed int &rData )=0; | ||
64 | virtual void read( unsigned long &rData )=0; | ||
65 | virtual void read( signed long &rData )=0; | ||
66 | virtual void read( unsigned long long &rData )=0; | ||
67 | virtual void read( signed long long &rData )=0; | ||
68 | virtual void read( float &rData )=0; | ||
69 | virtual void read( double &rData )=0; | ||
70 | virtual void read( long double &rData )=0; | ||
71 | virtual void read( Bu::Blob &rData )=0; | ||
72 | virtual void read( Bu::Text &rData )=0; | ||
73 | |||
36 | virtual void setProperty( const Bu::Blob &rKey, | 74 | virtual void setProperty( const Bu::Blob &rKey, |
37 | const Bu::Variant &rValue )=0; | 75 | const Bu::Variant &rValue )=0; |
38 | virtual Bu::Variant getProperty( const Bu::Blob &rKey ) const=0; | 76 | virtual Bu::Variant getProperty( const Bu::Blob &rKey ) const=0; |
@@ -65,6 +103,8 @@ namespace Bu | |||
65 | Archive &operator<<( Archive &ar, float p ); | 103 | Archive &operator<<( Archive &ar, float p ); |
66 | Archive &operator<<( Archive &ar, double p ); | 104 | Archive &operator<<( Archive &ar, double p ); |
67 | Archive &operator<<( Archive &ar, long double p ); | 105 | Archive &operator<<( Archive &ar, long double p ); |
106 | Archive &operator<<( Archive &ar, const Bu::Blob &p ); | ||
107 | Archive &operator<<( Archive &ar, const Bu::Text &p ); | ||
68 | 108 | ||
69 | Archive &operator>>( Archive &ar, bool &p ); | 109 | Archive &operator>>( Archive &ar, bool &p ); |
70 | Archive &operator>>( Archive &ar, char &p ); | 110 | Archive &operator>>( Archive &ar, char &p ); |
@@ -81,6 +121,8 @@ namespace Bu | |||
81 | Archive &operator>>( Archive &ar, float &p ); | 121 | Archive &operator>>( Archive &ar, float &p ); |
82 | Archive &operator>>( Archive &ar, double &p ); | 122 | Archive &operator>>( Archive &ar, double &p ); |
83 | Archive &operator>>( Archive &ar, long double &p ); | 123 | Archive &operator>>( Archive &ar, long double &p ); |
124 | Archive &operator>>( Archive &ar, Bu::Blob &p ); | ||
125 | Archive &operator>>( Archive &ar, Bu::Text &p ); | ||
84 | }; | 126 | }; |
85 | 127 | ||
86 | #endif | 128 | #endif |
diff --git a/src/stable/archivebinary.cpp b/src/stable/archivebinary.cpp index 3f05947..04e80d2 100644 --- a/src/stable/archivebinary.cpp +++ b/src/stable/archivebinary.cpp | |||
@@ -9,6 +9,7 @@ | |||
9 | #include "bu/stream.h" | 9 | #include "bu/stream.h" |
10 | 10 | ||
11 | #include "bu/sio.h" | 11 | #include "bu/sio.h" |
12 | #include "bu/text.h" | ||
12 | 13 | ||
13 | Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : | 14 | Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : |
14 | bLoading( bLoading ), | 15 | bLoading( bLoading ), |
@@ -20,7 +21,7 @@ Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : | |||
20 | Bu::ArchiveBinary::~ArchiveBinary() | 21 | Bu::ArchiveBinary::~ArchiveBinary() |
21 | { | 22 | { |
22 | } | 23 | } |
23 | 24 | /* | |
24 | void Bu::ArchiveBinary::write( const void *pData, size_t nSize ) | 25 | void Bu::ArchiveBinary::write( const void *pData, size_t nSize ) |
25 | { | 26 | { |
26 | if( nSize == 0 || pData == NULL ) | 27 | if( nSize == 0 || pData == NULL ) |
@@ -36,6 +37,193 @@ void Bu::ArchiveBinary::read( void *pData, size_t nSize ) | |||
36 | 37 | ||
37 | if( (size_t)rStream.read( (char *)pData, nSize ) < nSize ) | 38 | if( (size_t)rStream.read( (char *)pData, nSize ) < nSize ) |
38 | throw Bu::ExceptionBase("Insufficient data to unarchive object."); | 39 | throw Bu::ExceptionBase("Insufficient data to unarchive object."); |
40 | }*/ | ||
41 | |||
42 | void Bu::ArchiveBinary::write( bool rData ) | ||
43 | { | ||
44 | rStream.write( &rData, sizeof(rData) ); | ||
45 | } | ||
46 | |||
47 | void Bu::ArchiveBinary::write( const unsigned char rData ) | ||
48 | { | ||
49 | rStream.write( &rData, sizeof(rData) ); | ||
50 | } | ||
51 | |||
52 | void Bu::ArchiveBinary::write( char rData ) | ||
53 | { | ||
54 | rStream.write( &rData, sizeof(rData) ); | ||
55 | } | ||
56 | |||
57 | void Bu::ArchiveBinary::write( signed char rData ) | ||
58 | { | ||
59 | rStream.write( &rData, sizeof(rData) ); | ||
60 | } | ||
61 | |||
62 | void Bu::ArchiveBinary::write( unsigned short rData ) | ||
63 | { | ||
64 | rStream.write( &rData, sizeof(rData) ); | ||
65 | } | ||
66 | |||
67 | void Bu::ArchiveBinary::write( signed short rData ) | ||
68 | { | ||
69 | rStream.write( &rData, sizeof(rData) ); | ||
70 | } | ||
71 | |||
72 | void Bu::ArchiveBinary::write( unsigned int rData ) | ||
73 | { | ||
74 | rStream.write( &rData, sizeof(rData) ); | ||
75 | } | ||
76 | |||
77 | void Bu::ArchiveBinary::write( signed int rData ) | ||
78 | { | ||
79 | rStream.write( &rData, sizeof(rData) ); | ||
80 | } | ||
81 | |||
82 | void Bu::ArchiveBinary::write( unsigned long rData ) | ||
83 | { | ||
84 | rStream.write( &rData, sizeof(rData) ); | ||
85 | } | ||
86 | |||
87 | void Bu::ArchiveBinary::write( signed long rData ) | ||
88 | { | ||
89 | rStream.write( &rData, sizeof(rData) ); | ||
90 | } | ||
91 | |||
92 | void Bu::ArchiveBinary::write( unsigned long long rData ) | ||
93 | { | ||
94 | rStream.write( &rData, sizeof(rData) ); | ||
95 | } | ||
96 | |||
97 | void Bu::ArchiveBinary::write( signed long long rData ) | ||
98 | { | ||
99 | rStream.write( &rData, sizeof(rData) ); | ||
100 | } | ||
101 | |||
102 | void Bu::ArchiveBinary::write( float rData ) | ||
103 | { | ||
104 | rStream.write( &rData, sizeof(rData) ); | ||
105 | } | ||
106 | |||
107 | void Bu::ArchiveBinary::write( double rData ) | ||
108 | { | ||
109 | rStream.write( &rData, sizeof(rData) ); | ||
110 | } | ||
111 | |||
112 | void Bu::ArchiveBinary::write( long double rData ) | ||
113 | { | ||
114 | rStream.write( &rData, sizeof(rData) ); | ||
115 | } | ||
116 | |||
117 | void Bu::ArchiveBinary::write( const Bu::Blob &rData ) | ||
118 | { | ||
119 | int32_t iSize = rData.getSize(); | ||
120 | write( iSize ); | ||
121 | rStream.write( rData.getData(), iSize ); | ||
122 | } | ||
123 | |||
124 | void Bu::ArchiveBinary::write( const Bu::Text &rData ) | ||
125 | { | ||
126 | int32_t iSize = rData.getSize(); | ||
127 | write( iSize ); | ||
128 | rStream.write( rData.getData(), iSize ); | ||
129 | } | ||
130 | |||
131 | void Bu::ArchiveBinary::read( bool &rData ) | ||
132 | { | ||
133 | rStream.read( &rData, sizeof(rData) ); | ||
134 | } | ||
135 | |||
136 | void Bu::ArchiveBinary::read( unsigned char &rData ) | ||
137 | { | ||
138 | rStream.read( &rData, sizeof(rData) ); | ||
139 | } | ||
140 | |||
141 | void Bu::ArchiveBinary::read( char &rData ) | ||
142 | { | ||
143 | rStream.read( &rData, sizeof(rData) ); | ||
144 | } | ||
145 | |||
146 | void Bu::ArchiveBinary::read( signed char &rData ) | ||
147 | { | ||
148 | rStream.read( &rData, sizeof(rData) ); | ||
149 | } | ||
150 | |||
151 | void Bu::ArchiveBinary::read( unsigned short &rData ) | ||
152 | { | ||
153 | rStream.read( &rData, sizeof(rData) ); | ||
154 | } | ||
155 | |||
156 | void Bu::ArchiveBinary::read( signed short &rData ) | ||
157 | { | ||
158 | rStream.read( &rData, sizeof(rData) ); | ||
159 | } | ||
160 | |||
161 | void Bu::ArchiveBinary::read( unsigned int &rData ) | ||
162 | { | ||
163 | rStream.read( &rData, sizeof(rData) ); | ||
164 | } | ||
165 | |||
166 | void Bu::ArchiveBinary::read( signed int &rData ) | ||
167 | { | ||
168 | rStream.read( &rData, sizeof(rData) ); | ||
169 | } | ||
170 | |||
171 | void Bu::ArchiveBinary::read( unsigned long &rData ) | ||
172 | { | ||
173 | rStream.read( &rData, sizeof(rData) ); | ||
174 | } | ||
175 | |||
176 | void Bu::ArchiveBinary::read( signed long &rData ) | ||
177 | { | ||
178 | rStream.read( &rData, sizeof(rData) ); | ||
179 | } | ||
180 | |||
181 | void Bu::ArchiveBinary::read( unsigned long long &rData ) | ||
182 | { | ||
183 | rStream.read( &rData, sizeof(rData) ); | ||
184 | } | ||
185 | |||
186 | void Bu::ArchiveBinary::read( signed long long &rData ) | ||
187 | { | ||
188 | rStream.read( &rData, sizeof(rData) ); | ||
189 | } | ||
190 | |||
191 | void Bu::ArchiveBinary::read( float &rData ) | ||
192 | { | ||
193 | rStream.read( &rData, sizeof(rData) ); | ||
194 | } | ||
195 | |||
196 | void Bu::ArchiveBinary::read( double &rData ) | ||
197 | { | ||
198 | rStream.read( &rData, sizeof(rData) ); | ||
199 | } | ||
200 | |||
201 | void Bu::ArchiveBinary::read( long double &rData ) | ||
202 | { | ||
203 | rStream.read( &rData, sizeof(rData) ); | ||
204 | } | ||
205 | |||
206 | void Bu::ArchiveBinary::read( Bu::Blob &rData ) | ||
207 | { | ||
208 | int32_t iSize; | ||
209 | read( iSize ); | ||
210 | char *pBuf = new char[iSize]; | ||
211 | rStream.read( pBuf, iSize ); | ||
212 | rData.set( pBuf, iSize ); | ||
213 | delete[] pBuf; | ||
214 | } | ||
215 | |||
216 | void Bu::ArchiveBinary::read( Bu::Text &rData ) | ||
217 | { | ||
218 | /* | ||
219 | int32_t iSize; | ||
220 | read( iSize ); | ||
221 | char *pBuf = new char[iSize]; | ||
222 | rStream.read( pBuf, iSize ); | ||
223 | rData.set( pBuf, iSize ); | ||
224 | delete[] pBuf; | ||
225 | */ | ||
226 | throw Bu::ExceptionBase("Cannot read Bu::Text objects yet."); | ||
39 | } | 227 | } |
40 | 228 | ||
41 | void Bu::ArchiveBinary::close() | 229 | void Bu::ArchiveBinary::close() |
diff --git a/src/stable/archivebinary.h b/src/stable/archivebinary.h index 4c12e02..d28e5e7 100644 --- a/src/stable/archivebinary.h +++ b/src/stable/archivebinary.h | |||
@@ -77,8 +77,44 @@ namespace Bu | |||
77 | virtual ~ArchiveBinary(); | 77 | virtual ~ArchiveBinary(); |
78 | virtual void close(); | 78 | virtual void close(); |
79 | 79 | ||
80 | virtual void write( const void *pData, size_t iSize ); | 80 | //virtual void write( const void *pData, size_t iSize ); |
81 | virtual void read( void *pData, size_t iSize ); | 81 | //virtual void read( void *pData, size_t iSize ); |
82 | |||
83 | virtual void write( bool rData ); | ||
84 | virtual void write( unsigned char rData ); | ||
85 | virtual void write( char rData ); | ||
86 | virtual void write( signed char rData ); | ||
87 | virtual void write( unsigned short rData ); | ||
88 | virtual void write( signed short rData ); | ||
89 | virtual void write( unsigned int rData ); | ||
90 | virtual void write( signed int rData ); | ||
91 | virtual void write( unsigned long rData ); | ||
92 | virtual void write( signed long rData ); | ||
93 | virtual void write( unsigned long long rData ); | ||
94 | virtual void write( signed long long rData ); | ||
95 | virtual void write( float rData ); | ||
96 | virtual void write( double rData ); | ||
97 | virtual void write( long double rData ); | ||
98 | virtual void write( const Bu::Blob &rData ); | ||
99 | virtual void write( const Bu::Text &rData ); | ||
100 | |||
101 | virtual void read( bool &rData ); | ||
102 | virtual void read( unsigned char &rData ); | ||
103 | virtual void read( char &rData ); | ||
104 | virtual void read( signed char &rData ); | ||
105 | virtual void read( unsigned short &rData ); | ||
106 | virtual void read( signed short &rData ); | ||
107 | virtual void read( unsigned int &rData ); | ||
108 | virtual void read( signed int &rData ); | ||
109 | virtual void read( unsigned long &rData ); | ||
110 | virtual void read( signed long &rData ); | ||
111 | virtual void read( unsigned long long &rData ); | ||
112 | virtual void read( signed long long &rData ); | ||
113 | virtual void read( float &rData ); | ||
114 | virtual void read( double &rData ); | ||
115 | virtual void read( long double &rData ); | ||
116 | virtual void read( Bu::Blob &rData ); | ||
117 | virtual void read( Bu::Text &rData ); | ||
82 | 118 | ||
83 | /** | 119 | /** |
84 | * For storage, get an ID for the pointer to the object you're going to | 120 | * For storage, get an ID for the pointer to the object you're going to |
diff --git a/src/stable/crypt.cpp b/src/stable/crypt.cpp index 085d460..0dbe2d5 100644 --- a/src/stable/crypt.cpp +++ b/src/stable/crypt.cpp | |||
@@ -26,7 +26,7 @@ Bu::String Bu::cryptPass( const Bu::String &sPass, const Bu::String &sSalt ) | |||
26 | 26 | ||
27 | b64Out.stop(); | 27 | b64Out.stop(); |
28 | 28 | ||
29 | return sSaltSml + "$" + mbOut.getString(); | 29 | return sSaltSml + "$" + mbOut.getBlob(); |
30 | } | 30 | } |
31 | 31 | ||
32 | Bu::String Bu::cryptPass( const Bu::String &sPass ) | 32 | Bu::String Bu::cryptPass( const Bu::String &sPass ) |
@@ -42,6 +42,6 @@ Bu::String Bu::cryptPass( const Bu::String &sPass ) | |||
42 | 42 | ||
43 | b64Salt.stop(); | 43 | b64Salt.stop(); |
44 | 44 | ||
45 | return cryptPass( sPass, mbSalt.getString() ); | 45 | return cryptPass( sPass, mbSalt.getBlob() ); |
46 | } | 46 | } |
47 | 47 | ||
diff --git a/src/stable/membuf.cpp b/src/stable/membuf.cpp index 040c0c6..fff3027 100644 --- a/src/stable/membuf.cpp +++ b/src/stable/membuf.cpp | |||
@@ -169,6 +169,11 @@ Bu::String &Bu::MemBuf::getString() | |||
169 | return sBuf; | 169 | return sBuf; |
170 | } | 170 | } |
171 | 171 | ||
172 | Bu::Blob Bu::MemBuf::getBlob() | ||
173 | { | ||
174 | return Bu::Blob( sBuf.getStr(), sBuf.getSize() ); | ||
175 | } | ||
176 | |||
172 | void Bu::MemBuf::setString( const Bu::String &sNewData ) | 177 | void Bu::MemBuf::setString( const Bu::String &sNewData ) |
173 | { | 178 | { |
174 | sBuf = sNewData; | 179 | sBuf = sNewData; |
diff --git a/src/stable/membuf.h b/src/stable/membuf.h index fc9be1f..f42cc2d 100644 --- a/src/stable/membuf.h +++ b/src/stable/membuf.h | |||
@@ -13,6 +13,7 @@ | |||
13 | #include "bu/config.h" | 13 | #include "bu/config.h" |
14 | #include "bu/stream.h" | 14 | #include "bu/stream.h" |
15 | #include "bu/string.h" | 15 | #include "bu/string.h" |
16 | #include "bu/blob.h" | ||
16 | 17 | ||
17 | namespace Bu | 18 | namespace Bu |
18 | { | 19 | { |
@@ -57,6 +58,7 @@ namespace Bu | |||
57 | virtual Bu::String getLocation() const; | 58 | virtual Bu::String getLocation() const; |
58 | 59 | ||
59 | Bu::String &getString(); | 60 | Bu::String &getString(); |
61 | Bu::Blob getBlob(); | ||
60 | void setString( const Bu::String &sNewData ); | 62 | void setString( const Bu::String &sNewData ); |
61 | 63 | ||
62 | private: | 64 | private: |
diff --git a/src/stable/string.cpp b/src/stable/string.cpp index c36b768..81f2c7f 100644 --- a/src/stable/string.cpp +++ b/src/stable/string.cpp | |||
@@ -1520,20 +1520,18 @@ Bu::String &Bu::operator<<( Bu::String &dst, const Bu::String &sIn ) | |||
1520 | return dst; | 1520 | return dst; |
1521 | } | 1521 | } |
1522 | 1522 | ||
1523 | #include "bu/blob.h" | ||
1524 | |||
1523 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::String &s ) | 1525 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::String &s ) |
1524 | { | 1526 | { |
1525 | long n = s.getSize(); | 1527 | ar << Bu::Blob( s.getStr(), s.getSize() ); |
1526 | ar << n; | ||
1527 | ar.write( s.getConstStr(), n ); | ||
1528 | return ar; | 1528 | return ar; |
1529 | } | 1529 | } |
1530 | 1530 | ||
1531 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::String &s ) | 1531 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::String &s ) |
1532 | { | 1532 | { |
1533 | long n; | 1533 | Bu::Blob b; |
1534 | ar >> n; | 1534 | ar >> b; |
1535 | s.setSize( n ); | ||
1536 | ar.read( s.getStr(), n ); | ||
1537 | return ar; | 1535 | return ar; |
1538 | } | 1536 | } |
1539 | 1537 | ||
diff --git a/src/tests/archivetags.cpp b/src/tests/archivetags.cpp new file mode 100644 index 0000000..f0587fd --- /dev/null +++ b/src/tests/archivetags.cpp | |||
@@ -0,0 +1,73 @@ | |||
1 | |||
2 | class SubThing | ||
3 | { | ||
4 | public: | ||
5 | SubThing(); | ||
6 | virtual ~SubThing(); | ||
7 | |||
8 | Bu::Blob bData; | ||
9 | Bu::Text tName; | ||
10 | }; | ||
11 | |||
12 | class Something | ||
13 | { | ||
14 | pubilc: | ||
15 | Something(); | ||
16 | virtual ~Something(); | ||
17 | |||
18 | int iAge; | ||
19 | int iSize; | ||
20 | int *aiNumber; | ||
21 | SubThing xThing; | ||
22 | }; | ||
23 | |||
24 | Bu::Archive &operator<<( Bu::Archive &ar, const SubThing &st ) | ||
25 | { | ||
26 | Bu::Archive::Dictionary ds( ar ); | ||
27 | |||
28 | return ar | ||
29 | << ar.tag("data") << st.bData | ||
30 | << ar.tag("name") << st.tName; | ||
31 | } | ||
32 | |||
33 | Bu::Archive &operator>>( Bu::Archive &ar, SubThing &st ) | ||
34 | { | ||
35 | Bu::Archive::Dictionary ds( ar ); | ||
36 | |||
37 | return ar | ||
38 | >> ar.tag("data") >> st.bData | ||
39 | >> ar.tag("name") >> st.tName; | ||
40 | } | ||
41 | |||
42 | Bu::Archive &operator<<( Bu::Archive &ar, const Something &st ) | ||
43 | { | ||
44 | Bu::Archive::Dictionary ds( ar ); | ||
45 | ar << ar.tag("age") << st.iAge; | ||
46 | |||
47 | ar.startList("number", st.iSize ); | ||
48 | for( int j = 0; j < st.iSize; j++ ) | ||
49 | { | ||
50 | ar << st.aiNumber[j]; | ||
51 | } | ||
52 | ar.endList(); | ||
53 | ar << ar.tag("thing") << st.xThing; | ||
54 | return ar; | ||
55 | } | ||
56 | |||
57 | Bu::Archive &operator>>( Bu::Archive &ar, Something &st ) | ||
58 | { | ||
59 | Bu::Archive::Dictionary ds( ar ); | ||
60 | ar >> ar.tag("age") >> st.iAge; | ||
61 | |||
62 | ar.startList("number"); | ||
63 | int iSize = ar.getListSize(); | ||
64 | for( int j = 0; j < iSize; j++ ) | ||
65 | { | ||
66 | ar >> st.aiNumber[j]; | ||
67 | } | ||
68 | ar.endList(); | ||
69 | |||
70 | ar >> ar.tag("thing") >> st.xThing; | ||
71 | return ar; | ||
72 | } | ||
73 | |||
diff --git a/src/unstable/archivestream.cpp b/src/unstable/archivestream.cpp deleted file mode 100644 index 90a9599..0000000 --- a/src/unstable/archivestream.cpp +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2019 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/archivestream.h" | ||
9 | |||
10 | Bu::ArchiveStream::ArchiveStream( Bu::Archive &ar ) : | ||
11 | ar( ar ), | ||
12 | iPos( 0 ) | ||
13 | { | ||
14 | } | ||
15 | |||
16 | Bu::ArchiveStream::~ArchiveStream() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | void Bu::ArchiveStream::close() | ||
21 | { | ||
22 | ar.close(); | ||
23 | } | ||
24 | |||
25 | Bu::size Bu::ArchiveStream::read( void *pBuf, size iBytes ) | ||
26 | { | ||
27 | ar.read( pBuf, iBytes ); | ||
28 | iPos += iBytes; | ||
29 | return iBytes; | ||
30 | } | ||
31 | |||
32 | Bu::size Bu::ArchiveStream::write( const void *pBuf, size iBytes ) | ||
33 | { | ||
34 | ar.write( pBuf, iBytes ); | ||
35 | iPos += iBytes; | ||
36 | return iBytes; | ||
37 | } | ||
38 | |||
39 | Bu::size Bu::ArchiveStream::tell() | ||
40 | { | ||
41 | return iPos; | ||
42 | } | ||
43 | |||
44 | void Bu::ArchiveStream::seek( Bu::size ) | ||
45 | { | ||
46 | throw Bu::UnsupportedException(); | ||
47 | } | ||
48 | |||
49 | void Bu::ArchiveStream::setPos( Bu::size ) | ||
50 | { | ||
51 | throw Bu::UnsupportedException(); | ||
52 | } | ||
53 | |||
54 | void Bu::ArchiveStream::setPosEnd( Bu::size ) | ||
55 | { | ||
56 | throw Bu::UnsupportedException(); | ||
57 | } | ||
58 | |||
59 | bool Bu::ArchiveStream::isEos() | ||
60 | { | ||
61 | return false; | ||
62 | } | ||
63 | |||
64 | bool Bu::ArchiveStream::isOpen() | ||
65 | { | ||
66 | return true; | ||
67 | } | ||
68 | |||
69 | void Bu::ArchiveStream::flush() | ||
70 | { | ||
71 | } | ||
72 | |||
73 | bool Bu::ArchiveStream::canRead() | ||
74 | { | ||
75 | return true; | ||
76 | } | ||
77 | |||
78 | bool Bu::ArchiveStream::canWrite() | ||
79 | { | ||
80 | return true; | ||
81 | } | ||
82 | |||
83 | bool Bu::ArchiveStream::isReadable() | ||
84 | { | ||
85 | return true; | ||
86 | } | ||
87 | |||
88 | bool Bu::ArchiveStream::isWritable() | ||
89 | { | ||
90 | return true; | ||
91 | } | ||
92 | |||
93 | bool Bu::ArchiveStream::isSeekable() | ||
94 | { | ||
95 | return false; | ||
96 | } | ||
97 | |||
98 | bool Bu::ArchiveStream::isBlocking() | ||
99 | { | ||
100 | return false; | ||
101 | } | ||
102 | |||
103 | void Bu::ArchiveStream::setBlocking( bool ) | ||
104 | { | ||
105 | throw Bu::UnsupportedException(); | ||
106 | } | ||
107 | |||
108 | void Bu::ArchiveStream::setSize( Bu::size ) | ||
109 | { | ||
110 | throw Bu::UnsupportedException(); | ||
111 | } | ||
112 | |||
113 | Bu::size Bu::ArchiveStream::getSize() const | ||
114 | { | ||
115 | return iPos; | ||
116 | } | ||
117 | |||
118 | Bu::size Bu::ArchiveStream::getBlockSize() const | ||
119 | { | ||
120 | return 1; | ||
121 | } | ||
122 | |||
123 | Bu::String Bu::ArchiveStream::getLocation() const | ||
124 | { | ||
125 | return "Archive"; | ||
126 | } | ||
127 | |||
diff --git a/src/unstable/archivestream.h b/src/unstable/archivestream.h deleted file mode 100644 index da6c6b0..0000000 --- a/src/unstable/archivestream.h +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2019 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | #ifndef BU_ARCHIVE_STREAM_H | ||
8 | #define BU_ARCHIVE_STREAM_H | ||
9 | |||
10 | #include "bu/archive.h" | ||
11 | #include "bu/stream.h" | ||
12 | |||
13 | namespace Bu | ||
14 | { | ||
15 | class ArchiveStream : public Stream | ||
16 | { | ||
17 | public: | ||
18 | ArchiveStream( Bu::Archive &ar ); | ||
19 | virtual ~ArchiveStream(); | ||
20 | |||
21 | virtual void close(); | ||
22 | virtual size read( void *pBuf, size iBytes ); | ||
23 | virtual size write( const void *pBuf, size iBytes ); | ||
24 | virtual size tell(); | ||
25 | virtual void seek( size offset ); | ||
26 | virtual void setPos( size pos ); | ||
27 | virtual void setPosEnd( size pos ); | ||
28 | virtual bool isEos(); | ||
29 | virtual bool isOpen(); | ||
30 | virtual void flush(); | ||
31 | virtual bool canRead(); | ||
32 | virtual bool canWrite(); | ||
33 | virtual bool isReadable(); | ||
34 | virtual bool isWritable(); | ||
35 | virtual bool isSeekable(); | ||
36 | virtual bool isBlocking(); | ||
37 | virtual void setBlocking( bool bBlocking=true ); | ||
38 | virtual void setSize( size iSize ); | ||
39 | virtual size getSize() const; | ||
40 | virtual size getBlockSize() const; | ||
41 | virtual Bu::String getLocation() const; | ||
42 | |||
43 | private: | ||
44 | Bu::Archive &ar; | ||
45 | size iPos; | ||
46 | }; | ||
47 | } | ||
48 | |||
49 | #endif | ||
diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp index e72e265..51e74ff 100644 --- a/src/unstable/blob.cpp +++ b/src/unstable/blob.cpp | |||
@@ -142,6 +142,26 @@ bool Bu::Blob::isNullOrEmpty() const | |||
142 | return pData == NULL || iSize == 0; | 142 | return pData == NULL || iSize == 0; |
143 | } | 143 | } |
144 | 144 | ||
145 | void Bu::Blob::set( const Blob &rRhs ) | ||
146 | { | ||
147 | *this = rRhs; | ||
148 | } | ||
149 | |||
150 | void Bu::Blob::set( const char *pRhs ) | ||
151 | { | ||
152 | *this = pRhs; | ||
153 | } | ||
154 | |||
155 | void Bu::Blob::set( const char *pRhs, int32_t iSize ) | ||
156 | { | ||
157 | delete[] pData; | ||
158 | |||
159 | this->iSize = iSize; | ||
160 | pData = new char[iSize+1]; | ||
161 | memcpy( pData, pRhs, iSize ); | ||
162 | pData[iSize] = '\0'; | ||
163 | } | ||
164 | |||
145 | Bu::Blob &Bu::Blob::operator=( const Bu::Blob &rRhs ) | 165 | Bu::Blob &Bu::Blob::operator=( const Bu::Blob &rRhs ) |
146 | { | 166 | { |
147 | delete[] pData; | 167 | delete[] pData; |
diff --git a/src/unstable/blob.h b/src/unstable/blob.h index d6c40e3..214ab41 100644 --- a/src/unstable/blob.h +++ b/src/unstable/blob.h | |||
@@ -55,6 +55,9 @@ namespace Bu | |||
55 | bool isNull() const; | 55 | bool isNull() const; |
56 | bool isNullOrEmpty() const; | 56 | bool isNullOrEmpty() const; |
57 | 57 | ||
58 | void set( const Blob &rRhs ); | ||
59 | void set( const char *pRhs ); | ||
60 | void set( const char *pRhs, int32_t iSize ); | ||
58 | Blob &operator=( const Blob &rRhs ); | 61 | Blob &operator=( const Blob &rRhs ); |
59 | Blob &operator=( const char *pRhs ); | 62 | Blob &operator=( const char *pRhs ); |
60 | 63 | ||
diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp index 6642d75..9708423 100644 --- a/src/unstable/uuid.cpp +++ b/src/unstable/uuid.cpp | |||
@@ -10,6 +10,8 @@ | |||
10 | #include "bu/formatter.h" | 10 | #include "bu/formatter.h" |
11 | #include "bu/membuf.h" | 11 | #include "bu/membuf.h" |
12 | #include "bu/random.h" | 12 | #include "bu/random.h" |
13 | #include "bu/archive.h" | ||
14 | #include "bu/blobbuilder.h" | ||
13 | #include <string.h> | 15 | #include <string.h> |
14 | 16 | ||
15 | #ifdef WIN32 | 17 | #ifdef WIN32 |
@@ -27,11 +29,11 @@ Bu::Uuid::Uuid( const Uuid &src ) | |||
27 | memcpy( data, src.data, 16 ); | 29 | memcpy( data, src.data, 16 ); |
28 | } | 30 | } |
29 | 31 | ||
30 | Bu::Uuid::Uuid( const Bu::String &sSrc ) | 32 | Bu::Uuid::Uuid( const Bu::Blob &sSrc ) |
31 | { | 33 | { |
32 | if( sSrc.getSize() == 16 ) | 34 | if( sSrc.getSize() == 16 ) |
33 | { | 35 | { |
34 | memcpy( data, sSrc.getStr(), 16 ); | 36 | memcpy( data, sSrc.getData(), 16 ); |
35 | } | 37 | } |
36 | else if( sSrc.getSize() == 36 ) | 38 | else if( sSrc.getSize() == 36 ) |
37 | { | 39 | { |
@@ -44,12 +46,12 @@ Bu::Uuid::~Uuid() | |||
44 | { | 46 | { |
45 | } | 47 | } |
46 | 48 | ||
47 | Bu::String Bu::Uuid::toRawString() const | 49 | Bu::Blob Bu::Uuid::toRawBlob() const |
48 | { | 50 | { |
49 | return Bu::String( (char *)data, 16 ); | 51 | return Bu::Blob( (char *)data, 16 ); |
50 | } | 52 | } |
51 | 53 | ||
52 | Bu::String Bu::Uuid::toString() const | 54 | Bu::Blob Bu::Uuid::toBlob() const |
53 | { | 55 | { |
54 | Bu::MemBuf mb; | 56 | Bu::MemBuf mb; |
55 | Bu::Formatter f( mb ); | 57 | Bu::Formatter f( mb ); |
@@ -61,12 +63,14 @@ Bu::String Bu::Uuid::toString() const | |||
61 | f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j]; | 63 | f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j]; |
62 | } | 64 | } |
63 | 65 | ||
64 | return mb.getString(); | 66 | return mb.getBlob(); |
65 | } | 67 | } |
66 | 68 | ||
67 | Bu::String Bu::Uuid::toUrn() const | 69 | Bu::Blob Bu::Uuid::toUrn() const |
68 | { | 70 | { |
69 | return "urn:uuid:" + toString(); | 71 | BlobBuilder bb("urn:uuid:"); |
72 | bb.append( toBlob() ); | ||
73 | return bb.getBlob(); | ||
70 | } | 74 | } |
71 | 75 | ||
72 | int Bu::Uuid::getVersion() | 76 | int Bu::Uuid::getVersion() |
@@ -129,9 +133,9 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType ) | |||
129 | return id; | 133 | return id; |
130 | } | 134 | } |
131 | 135 | ||
132 | void Bu::Uuid::set( const Bu::String &sSrc ) | 136 | void Bu::Uuid::set( const Bu::Blob &sSrc ) |
133 | { | 137 | { |
134 | const char *dat = sSrc.getStr(); | 138 | const char *dat = sSrc.getData(); |
135 | int iNibble = 0; | 139 | int iNibble = 0; |
136 | memset( data, 0, 16 ); | 140 | memset( data, 0, 16 ); |
137 | for( int j = 0; j < 36; j++ ) | 141 | for( int j = 0; j < 36; j++ ) |
@@ -162,7 +166,7 @@ Bu::Uuid &Bu::Uuid::operator=( const Uuid &rhs ) | |||
162 | 166 | ||
163 | template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) | 167 | template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) |
164 | { | 168 | { |
165 | return __calcHashCode<String>( k.toRawString() ); | 169 | return __calcHashCode<Blob>( k.toRawBlob() ); |
166 | } | 170 | } |
167 | 171 | ||
168 | template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &b ) | 172 | template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &b ) |
@@ -172,18 +176,20 @@ template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid & | |||
172 | 176 | ||
173 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u ) | 177 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u ) |
174 | { | 178 | { |
175 | ar.read( u.data, 16 ); | 179 | Bu::Blob b; |
180 | ar >> b; | ||
181 | memcpy( b.getData(), u.data, 16 ); | ||
176 | return ar; | 182 | return ar; |
177 | } | 183 | } |
178 | 184 | ||
179 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u ) | 185 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u ) |
180 | { | 186 | { |
181 | ar.write( u.data, 16 ); | 187 | ar << u.toRawBlob(); |
182 | return ar; | 188 | return ar; |
183 | } | 189 | } |
184 | 190 | ||
185 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u ) | 191 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u ) |
186 | { | 192 | { |
187 | return f << u.toString(); | 193 | return f << u.toBlob(); |
188 | } | 194 | } |
189 | 195 | ||
diff --git a/src/unstable/uuid.h b/src/unstable/uuid.h index d61a928..902942e 100644 --- a/src/unstable/uuid.h +++ b/src/unstable/uuid.h | |||
@@ -9,10 +9,11 @@ | |||
9 | #define BU_UUID_H | 9 | #define BU_UUID_H |
10 | 10 | ||
11 | #include "bu/util.h" | 11 | #include "bu/util.h" |
12 | #include "bu/string.h" | 12 | #include "bu/blob.h" |
13 | 13 | ||
14 | namespace Bu | 14 | namespace Bu |
15 | { | 15 | { |
16 | class Archive; | ||
16 | class Uuid | 17 | class Uuid |
17 | { | 18 | { |
18 | friend Bu::Archive &operator>>( Bu::Archive &ar, Uuid &u ); | 19 | friend Bu::Archive &operator>>( Bu::Archive &ar, Uuid &u ); |
@@ -20,12 +21,12 @@ namespace Bu | |||
20 | public: | 21 | public: |
21 | Uuid(); | 22 | Uuid(); |
22 | Uuid( const Uuid &src ); | 23 | Uuid( const Uuid &src ); |
23 | Uuid( const Bu::String &sSrc ); | 24 | Uuid( const Bu::Blob &sSrc ); |
24 | virtual ~Uuid(); | 25 | virtual ~Uuid(); |
25 | 26 | ||
26 | Bu::String toRawString() const; | 27 | Bu::Blob toRawBlob() const; |
27 | Bu::String toString() const; | 28 | Bu::Blob toBlob() const; |
28 | Bu::String toUrn() const; | 29 | Bu::Blob toUrn() const; |
29 | 30 | ||
30 | enum Type | 31 | enum Type |
31 | { | 32 | { |
@@ -43,11 +44,11 @@ namespace Bu | |||
43 | DEPRECATED static Uuid gen() { return generate(); } | 44 | DEPRECATED static Uuid gen() { return generate(); } |
44 | 45 | ||
45 | void clear(); | 46 | void clear(); |
46 | void set( const Bu::String &sSrc ); | 47 | void set( const Bu::Blob &sSrc ); |
47 | 48 | ||
48 | bool operator==( const Uuid &rhs ) const; | 49 | bool operator==( const Uuid &rhs ) const; |
49 | bool operator!=( const Uuid &rhs ) const; | 50 | bool operator!=( const Uuid &rhs ) const; |
50 | Uuid &operator=( const Bu::String &rhs ) { set( rhs ); return *this; } | 51 | Uuid &operator=( const Bu::Blob &rhs ) { set( rhs ); return *this; } |
51 | Uuid &operator=( const Uuid &rhs ); | 52 | Uuid &operator=( const Uuid &rhs ); |
52 | 53 | ||
53 | private: | 54 | private: |