1 | /*
|
---|
2 | * Copyright 2003,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Log: XSerializeEngine.hpp,v $
|
---|
19 | * Revision 1.18 2004/09/08 13:56:14 peiyongz
|
---|
20 | * Apache License Version 2.0
|
---|
21 | *
|
---|
22 | * Revision 1.17 2004/03/05 22:21:45 peiyongz
|
---|
23 | * readBytes()/writeBytes between BinOutputStream/BinInputStream and
|
---|
24 | * XSerializeEngine will always be the full size of the buffer to maintain the exact
|
---|
25 | * position for aligned data.
|
---|
26 | *
|
---|
27 | * Revision 1.16 2004/03/01 23:19:03 peiyongz
|
---|
28 | * Grant XSerializeEngine access to GrammarPool
|
---|
29 | *
|
---|
30 | * Revision 1.15 2004/02/20 20:57:39 peiyongz
|
---|
31 | * Bug#27046: path from David Bertoni
|
---|
32 | *
|
---|
33 | * Revision 1.14 2004/02/11 20:38:50 peiyongz
|
---|
34 | * Fix to bug#26864, thanks to David Bertoni.
|
---|
35 | *
|
---|
36 | * Revision 1.13 2004/01/29 11:46:30 cargilld
|
---|
37 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
38 | *
|
---|
39 | * Revision 1.12 2004/01/16 21:55:18 peiyongz
|
---|
40 | * maintain the same size on both 32/64 bit architecture
|
---|
41 | *
|
---|
42 | * Revision 1.11 2004/01/15 23:42:32 peiyongz
|
---|
43 | * proper allignment for built-in datatype read/write
|
---|
44 | *
|
---|
45 | * Revision 1.10 2003/12/17 00:18:34 cargilld
|
---|
46 | * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
|
---|
47 | *
|
---|
48 | * Revision 1.9 2003/11/25 20:37:40 jberry
|
---|
49 | * Cleanup build errors/warnings from CodeWarrior
|
---|
50 | *
|
---|
51 | * Revision 1.8 2003/11/11 22:48:13 knoaman
|
---|
52 | * Serialization of XSAnnotation.
|
---|
53 | *
|
---|
54 | * Revision 1.7 2003/10/17 21:09:03 peiyongz
|
---|
55 | * renaming methods
|
---|
56 | *
|
---|
57 | * Revision 1.6 2003/10/14 15:18:20 peiyongz
|
---|
58 | * getMemoryManager()
|
---|
59 | *
|
---|
60 | * Revision 1.5 2003/10/09 19:11:53 peiyongz
|
---|
61 | * Fix to linkage error on Solaris
|
---|
62 | *
|
---|
63 | * Revision 1.4 2003/10/07 19:38:31 peiyongz
|
---|
64 | * API for Template_Class Object Serialization/Deserialization
|
---|
65 | *
|
---|
66 | * Revision 1.3 2003/09/25 22:22:00 peiyongz
|
---|
67 | * Introduction of readString/writeString
|
---|
68 | *
|
---|
69 | * Revision 1.2 2003/09/19 04:29:11 neilg
|
---|
70 | * fix compilation problems under GCC
|
---|
71 | *
|
---|
72 | * Revision 1.1 2003/09/18 18:31:24 peiyongz
|
---|
73 | * OSU: Object Serialization Utilities
|
---|
74 | *
|
---|
75 | * $Id: XSerializeEngine.hpp,v 1.18 2004/09/08 13:56:14 peiyongz Exp $
|
---|
76 | *
|
---|
77 | */
|
---|
78 |
|
---|
79 | #if !defined(XSERIALIZE_ENGINE_HPP)
|
---|
80 | #define XSERIALIZE_ENGINE_HPP
|
---|
81 |
|
---|
82 | #include <xercesc/util/RefHashTableOf.hpp>
|
---|
83 | #include <xercesc/util/ValueVectorOf.hpp>
|
---|
84 | #include <xercesc/util/XMLExceptMsgs.hpp>
|
---|
85 |
|
---|
86 | #include <xercesc/internal/XSerializationException.hpp>
|
---|
87 |
|
---|
88 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
89 |
|
---|
90 | class XSerializable;
|
---|
91 | class XProtoType;
|
---|
92 | class MemoryManager;
|
---|
93 | class XSerializedObjectId;
|
---|
94 | class BinOutputStream;
|
---|
95 | class BinInputStream;
|
---|
96 | class XMLGrammarPool;
|
---|
97 | class XMLStringPool;
|
---|
98 |
|
---|
99 | class XMLUTIL_EXPORT XSerializeEngine
|
---|
100 | {
|
---|
101 | public:
|
---|
102 |
|
---|
103 | enum { mode_Store
|
---|
104 | , mode_Load
|
---|
105 | };
|
---|
106 |
|
---|
107 |
|
---|
108 | static const bool toReadBufferLen;
|
---|
109 |
|
---|
110 | typedef unsigned int XSerializedObjectId_t;
|
---|
111 |
|
---|
112 | /***
|
---|
113 | *
|
---|
114 | * Destructor
|
---|
115 | *
|
---|
116 | ***/
|
---|
117 | ~XSerializeEngine();
|
---|
118 |
|
---|
119 | /***
|
---|
120 | *
|
---|
121 | * Constructor for de-serialization(loading)
|
---|
122 | *
|
---|
123 | * Application needs to make sure that the instance of
|
---|
124 | * BinInputStream, persists beyond the life of this
|
---|
125 | * SerializeEngine.
|
---|
126 | *
|
---|
127 | * Param
|
---|
128 | * inStream input stream
|
---|
129 | * gramPool Grammar Pool
|
---|
130 | * bufSize the size of the internal buffer
|
---|
131 | *
|
---|
132 | ***/
|
---|
133 | XSerializeEngine(BinInputStream* inStream
|
---|
134 | , XMLGrammarPool* const gramPool
|
---|
135 | , unsigned long bufSize = 8192 );
|
---|
136 |
|
---|
137 |
|
---|
138 | /***
|
---|
139 | *
|
---|
140 | * Constructor for serialization(storing)
|
---|
141 | *
|
---|
142 | * Application needs to make sure that the instance of
|
---|
143 | * BinOutputStream, persists beyond the life of this
|
---|
144 | * SerializeEngine.
|
---|
145 | *
|
---|
146 | * Param
|
---|
147 | * outStream output stream
|
---|
148 | * gramPool Grammar Pool
|
---|
149 | * bufSize the size of the internal buffer
|
---|
150 | *
|
---|
151 | ***/
|
---|
152 | XSerializeEngine(BinOutputStream* outStream
|
---|
153 | , XMLGrammarPool* const gramPool
|
---|
154 | , unsigned long bufSize = 8192 );
|
---|
155 |
|
---|
156 |
|
---|
157 | /***
|
---|
158 | *
|
---|
159 | * Deprecated
|
---|
160 | *
|
---|
161 | * Constructor for de-serialization(loading)
|
---|
162 | *
|
---|
163 | * Application needs to make sure that the instance of
|
---|
164 | * BinInputStream, persists beyond the life of this
|
---|
165 | * SerializeEngine.
|
---|
166 | *
|
---|
167 | * Param
|
---|
168 | * inStream input stream
|
---|
169 | * manager MemoryManager
|
---|
170 | * bufSize the size of the internal buffer
|
---|
171 | *
|
---|
172 | ***/
|
---|
173 | XSerializeEngine(BinInputStream* inStream
|
---|
174 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
175 | , unsigned long bufSize = 8192 );
|
---|
176 |
|
---|
177 |
|
---|
178 | /***
|
---|
179 | *
|
---|
180 | * Deprecated
|
---|
181 | *
|
---|
182 | * Constructor for serialization(storing)
|
---|
183 | *
|
---|
184 | * Application needs to make sure that the instance of
|
---|
185 | * BinOutputStream, persists beyond the life of this
|
---|
186 | * SerializeEngine.
|
---|
187 | *
|
---|
188 | * Param
|
---|
189 | * outStream output stream
|
---|
190 | * manager MemoryManager
|
---|
191 | * bufSize the size of the internal buffer
|
---|
192 | *
|
---|
193 | ***/
|
---|
194 | XSerializeEngine(BinOutputStream* outStream
|
---|
195 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
196 | , unsigned long bufSize = 8192 );
|
---|
197 |
|
---|
198 | /***
|
---|
199 | *
|
---|
200 | * When serialization, flush out the internal buffer
|
---|
201 | *
|
---|
202 | * Return:
|
---|
203 | *
|
---|
204 | ***/
|
---|
205 | void flush();
|
---|
206 |
|
---|
207 | /***
|
---|
208 | *
|
---|
209 | * Checking if the serialize engine is doing serialization(storing)
|
---|
210 | *
|
---|
211 | * Return: true, if it is
|
---|
212 | * false, otherwise
|
---|
213 | *
|
---|
214 | ***/
|
---|
215 | inline bool isStoring() const;
|
---|
216 |
|
---|
217 | /***
|
---|
218 | *
|
---|
219 | * Checking if the serialize engine is doing de-serialization(loading)
|
---|
220 | *
|
---|
221 | * Return: true, if it is
|
---|
222 | * false, otherwise
|
---|
223 | *
|
---|
224 | ***/
|
---|
225 | inline bool isLoading() const;
|
---|
226 |
|
---|
227 | /***
|
---|
228 | *
|
---|
229 | * Get the GrammarPool
|
---|
230 | *
|
---|
231 | * Return: XMLGrammarPool
|
---|
232 | *
|
---|
233 | ***/
|
---|
234 | XMLGrammarPool* getGrammarPool() const;
|
---|
235 |
|
---|
236 | /***
|
---|
237 | *
|
---|
238 | * Get the StringPool
|
---|
239 | *
|
---|
240 | * Return: XMLStringPool
|
---|
241 | *
|
---|
242 | ***/
|
---|
243 | XMLStringPool* getStringPool() const;
|
---|
244 |
|
---|
245 | /***
|
---|
246 | *
|
---|
247 | * Get the embeded Memory Manager
|
---|
248 | *
|
---|
249 | * Return: MemoryManager
|
---|
250 | *
|
---|
251 | ***/
|
---|
252 | MemoryManager* getMemoryManager() const;
|
---|
253 |
|
---|
254 | /***
|
---|
255 | *
|
---|
256 | * Write object to the internal buffer.
|
---|
257 | *
|
---|
258 | * Param
|
---|
259 | * objectToWrite: the object to be serialized
|
---|
260 | *
|
---|
261 | * Return:
|
---|
262 | *
|
---|
263 | ***/
|
---|
264 | void write(XSerializable* const objectToWrite);
|
---|
265 |
|
---|
266 | /***
|
---|
267 | *
|
---|
268 | * Write prototype info to the internal buffer.
|
---|
269 | *
|
---|
270 | * Param
|
---|
271 | * protoType: instance of prototype
|
---|
272 | *
|
---|
273 | * Return:
|
---|
274 | *
|
---|
275 | ***/
|
---|
276 | void write(XProtoType* const protoType);
|
---|
277 |
|
---|
278 | /***
|
---|
279 | *
|
---|
280 | * Write a stream of XMLByte to the internal buffer.
|
---|
281 | *
|
---|
282 | * Param
|
---|
283 | * toWrite: the stream of XMLByte to write
|
---|
284 | * writeLen: the length of the stream
|
---|
285 | *
|
---|
286 | * Return:
|
---|
287 | *
|
---|
288 | ***/
|
---|
289 | void write(const XMLByte* const toWrite
|
---|
290 | , int writeLen);
|
---|
291 |
|
---|
292 | /***
|
---|
293 | *
|
---|
294 | * Write a stream of XMLCh to the internal buffer.
|
---|
295 | *
|
---|
296 | * Param
|
---|
297 | * toWrite: the stream of XMLCh to write
|
---|
298 | * writeLen: the length of the stream
|
---|
299 | *
|
---|
300 | * Return:
|
---|
301 | *
|
---|
302 | ***/
|
---|
303 | void write(const XMLCh* const toWrite
|
---|
304 | , int writeLen);
|
---|
305 |
|
---|
306 | /***
|
---|
307 | *
|
---|
308 | * Write a stream of XMLCh to the internal buffer.
|
---|
309 | *
|
---|
310 | * Write the bufferLen first if requested, then the length
|
---|
311 | * of the stream followed by the stream.
|
---|
312 | *
|
---|
313 | * Param
|
---|
314 | * toWrite: the stream of XMLCh to write
|
---|
315 | * bufferLen: the maximum size of the buffer
|
---|
316 | * toWriteBufLen: specify if the bufferLen need to be written or not
|
---|
317 | *
|
---|
318 | * Return:
|
---|
319 | *
|
---|
320 | ***/
|
---|
321 | void writeString(const XMLCh* const toWrite
|
---|
322 | , const int bufferLen = 0
|
---|
323 | , bool toWriteBufLen = false);
|
---|
324 |
|
---|
325 | /***
|
---|
326 | *
|
---|
327 | * Write a stream of XMLByte to the internal buffer.
|
---|
328 | *
|
---|
329 | * Write the bufferLen first if requested, then the length
|
---|
330 | * of the stream followed by the stream.
|
---|
331 | *
|
---|
332 | * Param
|
---|
333 | * toWrite: the stream of XMLByte to write
|
---|
334 | * bufferLen: the maximum size of the buffer
|
---|
335 | * toWriteBufLen: specify if the bufferLen need to be written or not
|
---|
336 | *
|
---|
337 | * Return:
|
---|
338 | *
|
---|
339 | ***/
|
---|
340 | void writeString(const XMLByte* const toWrite
|
---|
341 | , const int bufferLen = 0
|
---|
342 | , bool toWriteBufLen = false);
|
---|
343 |
|
---|
344 | static const bool toWriteBufferLen;
|
---|
345 |
|
---|
346 | /***
|
---|
347 | *
|
---|
348 | * Read/Create object from the internal buffer.
|
---|
349 | *
|
---|
350 | * Param
|
---|
351 | * protoType: an instance of prototype of the object anticipated
|
---|
352 | *
|
---|
353 | * Return: to object read/created
|
---|
354 | *
|
---|
355 | ***/
|
---|
356 | XSerializable* read(XProtoType* const protoType);
|
---|
357 |
|
---|
358 | /***
|
---|
359 | *
|
---|
360 | * Read prototype object from the internal buffer.
|
---|
361 | * Verify if the same prototype object found in buffer.
|
---|
362 | *
|
---|
363 | * Param
|
---|
364 | * protoType: an instance of prototype of the object anticipated
|
---|
365 | * objTag: the object Tag to an existing object
|
---|
366 | *
|
---|
367 | * Return: true : if matching found
|
---|
368 | * false : otherwise
|
---|
369 | *
|
---|
370 | ***/
|
---|
371 | bool read(XProtoType* const protoType
|
---|
372 | , XSerializedObjectId_t* objTag);
|
---|
373 |
|
---|
374 | /***
|
---|
375 | *
|
---|
376 | * Read XMLByte stream from the internal buffer.
|
---|
377 | *
|
---|
378 | * Param
|
---|
379 | * toRead: the buffer to hold the XMLByte stream
|
---|
380 | * readLen: the length of the XMLByte to read in
|
---|
381 | *
|
---|
382 | * Return:
|
---|
383 | *
|
---|
384 | ***/
|
---|
385 | void read(XMLByte* const toRead
|
---|
386 | , int readLen);
|
---|
387 |
|
---|
388 | /***
|
---|
389 | *
|
---|
390 | * Read XMLCh stream from the internal buffer.
|
---|
391 | *
|
---|
392 | * Param
|
---|
393 | * toRead: the buffer to hold the XMLCh stream
|
---|
394 | * readLen: the length of the XMLCh to read in
|
---|
395 | *
|
---|
396 | * Return:
|
---|
397 | *
|
---|
398 | ***/
|
---|
399 | void read(XMLCh* const toRead
|
---|
400 | , int readLen);
|
---|
401 |
|
---|
402 | /***
|
---|
403 | *
|
---|
404 | * Read a stream of XMLCh from the internal buffer.
|
---|
405 | *
|
---|
406 | * Read the bufferLen first if requested, then the length
|
---|
407 | * of the stream followed by the stream.
|
---|
408 | *
|
---|
409 | * Param
|
---|
410 | * toRead: the pointer to the buffer to hold the XMLCh stream
|
---|
411 | * bufferLen: the size of the buffer created
|
---|
412 | * dataLen: the length of the stream
|
---|
413 | * toReadBufLen: specify if the bufferLen need to be read or not
|
---|
414 | *
|
---|
415 | * Return:
|
---|
416 | *
|
---|
417 | ***/
|
---|
418 | void readString(XMLCh*& toRead
|
---|
419 | , int& bufferLen
|
---|
420 | , int& dataLen
|
---|
421 | , bool toReadBufLen = false);
|
---|
422 |
|
---|
423 | /***
|
---|
424 | *
|
---|
425 | * Read a stream of XMLCh from the internal buffer.
|
---|
426 | *
|
---|
427 | * Read the bufferLen first if requested, then the length
|
---|
428 | * of the stream followed by the stream.
|
---|
429 | *
|
---|
430 | * Param
|
---|
431 | * toRead: the pointer to the buffer to hold the XMLCh stream
|
---|
432 | * bufferLen: the size of the buffer created
|
---|
433 | *
|
---|
434 | * Return:
|
---|
435 | *
|
---|
436 | ***/
|
---|
437 | inline void readString(XMLCh*& toRead
|
---|
438 | , int& bufferLen);
|
---|
439 |
|
---|
440 | /***
|
---|
441 | *
|
---|
442 | * Read a stream of XMLCh from the internal buffer.
|
---|
443 | *
|
---|
444 | * Param
|
---|
445 | * toRead: the pointer to the buffer to hold the XMLCh stream
|
---|
446 | *
|
---|
447 | * Return:
|
---|
448 | *
|
---|
449 | ***/
|
---|
450 | inline void readString(XMLCh*& toRead);
|
---|
451 |
|
---|
452 | /***
|
---|
453 | *
|
---|
454 | * Read a stream of XMLByte from the internal buffer.
|
---|
455 | *
|
---|
456 | * Read the bufferLen first if requested, then the length
|
---|
457 | * of the stream followed by the stream.
|
---|
458 | *
|
---|
459 | * Param
|
---|
460 | * toRead: the pointer to the buffer to hold the XMLByte stream
|
---|
461 | * bufferLen: the size of the buffer created
|
---|
462 | * dataLen: the length of the stream
|
---|
463 | * toReadBufLen: specify if the bufferLen need to be read or not
|
---|
464 | *
|
---|
465 | * Return:
|
---|
466 | *
|
---|
467 | ***/
|
---|
468 | void readString(XMLByte*& toRead
|
---|
469 | , int& bufferLen
|
---|
470 | , int& dataLen
|
---|
471 | , bool toReadBufLen = false);
|
---|
472 |
|
---|
473 |
|
---|
474 | /***
|
---|
475 | *
|
---|
476 | * Read a stream of XMLByte from the internal buffer.
|
---|
477 | *
|
---|
478 | * Read the bufferLen first if requested, then the length
|
---|
479 | * of the stream followed by the stream.
|
---|
480 | *
|
---|
481 | * Param
|
---|
482 | * toRead: the pointer to the buffer to hold the XMLByte stream
|
---|
483 | * bufferLen: the size of the buffer created
|
---|
484 | *
|
---|
485 | * Return:
|
---|
486 | *
|
---|
487 | ***/
|
---|
488 | inline void readString(XMLByte*& toRead
|
---|
489 | , int& bufferLen);
|
---|
490 |
|
---|
491 | /***
|
---|
492 | *
|
---|
493 | * Read a stream of XMLByte from the internal buffer.
|
---|
494 | *
|
---|
495 | * Read the bufferLen first if requested, then the length
|
---|
496 | * of the stream followed by the stream.
|
---|
497 | *
|
---|
498 | * Param
|
---|
499 | * toRead: the pointer to the buffer to hold the XMLByte stream
|
---|
500 | * bufferLen: the size of the buffer created
|
---|
501 | * dataLen: the length of the stream
|
---|
502 | * toReadBufLen: specify if the bufferLen need to be read or not
|
---|
503 | *
|
---|
504 | * Return:
|
---|
505 | *
|
---|
506 | ***/
|
---|
507 | inline void readString(XMLByte*& toRead);
|
---|
508 |
|
---|
509 | /***
|
---|
510 | *
|
---|
511 | * Check if the template object has been stored or not
|
---|
512 | *
|
---|
513 | * Param
|
---|
514 | * objectPtr: the template object pointer
|
---|
515 | *
|
---|
516 | * Return: true : the object has NOT been stored yet
|
---|
517 | * false : otherwise
|
---|
518 | *
|
---|
519 | ***/
|
---|
520 | bool needToStoreObject(void* const templateObjectToWrite);
|
---|
521 |
|
---|
522 | /***
|
---|
523 | *
|
---|
524 | * Check if the template object has been loaded or not
|
---|
525 | *
|
---|
526 | * Param
|
---|
527 | * objectPtr: the address of the template object pointer
|
---|
528 | *
|
---|
529 | * Return: true : the object has NOT been loaded yet
|
---|
530 | * false : otherwise
|
---|
531 | *
|
---|
532 | ***/
|
---|
533 | bool needToLoadObject(void** templateObjectToRead);
|
---|
534 |
|
---|
535 | /***
|
---|
536 | *
|
---|
537 | * In the case of needToLoadObject() return true, the client
|
---|
538 | * application needs to instantiate an expected template object, and
|
---|
539 | * register the address to the engine.
|
---|
540 | *
|
---|
541 | * Param
|
---|
542 | * objectPtr: the template object pointer newly instantiated
|
---|
543 | *
|
---|
544 | * Return:
|
---|
545 | *
|
---|
546 | ***/
|
---|
547 | void registerObject(void* const templateObjectToRegister);
|
---|
548 |
|
---|
549 | /***
|
---|
550 | *
|
---|
551 | * Insertion operator for serializable classes
|
---|
552 | *
|
---|
553 | ***/
|
---|
554 |
|
---|
555 | friend XSerializeEngine& operator<<(XSerializeEngine&
|
---|
556 | , XSerializable* const );
|
---|
557 |
|
---|
558 | /***
|
---|
559 | *
|
---|
560 | * Insertion operators for
|
---|
561 | * . basic Xerces data types
|
---|
562 | * . built-in types
|
---|
563 | *
|
---|
564 | ***/
|
---|
565 | XSerializeEngine& operator<<(XMLByte);
|
---|
566 | XSerializeEngine& operator<<(XMLCh);
|
---|
567 |
|
---|
568 | XSerializeEngine& operator<<(char);
|
---|
569 | XSerializeEngine& operator<<(short);
|
---|
570 | XSerializeEngine& operator<<(int);
|
---|
571 | XSerializeEngine& operator<<(unsigned int);
|
---|
572 | XSerializeEngine& operator<<(long);
|
---|
573 | XSerializeEngine& operator<<(unsigned long);
|
---|
574 | XSerializeEngine& operator<<(float);
|
---|
575 | XSerializeEngine& operator<<(double);
|
---|
576 | XSerializeEngine& operator<<(bool);
|
---|
577 |
|
---|
578 | /***
|
---|
579 | *
|
---|
580 | * Extraction operators for
|
---|
581 | * . basic Xerces data types
|
---|
582 | * . built-in types
|
---|
583 | *
|
---|
584 | ***/
|
---|
585 | XSerializeEngine& operator>>(XMLByte&);
|
---|
586 | XSerializeEngine& operator>>(XMLCh&);
|
---|
587 |
|
---|
588 | XSerializeEngine& operator>>(char&);
|
---|
589 | XSerializeEngine& operator>>(short&);
|
---|
590 | XSerializeEngine& operator>>(int&);
|
---|
591 | XSerializeEngine& operator>>(unsigned int&);
|
---|
592 | XSerializeEngine& operator>>(long&);
|
---|
593 | XSerializeEngine& operator>>(unsigned long&);
|
---|
594 | XSerializeEngine& operator>>(float&);
|
---|
595 | XSerializeEngine& operator>>(double&);
|
---|
596 | XSerializeEngine& operator>>(bool&);
|
---|
597 |
|
---|
598 | private:
|
---|
599 | // -----------------------------------------------------------------------
|
---|
600 | // Unimplemented constructors and operators
|
---|
601 | // -----------------------------------------------------------------------
|
---|
602 | XSerializeEngine();
|
---|
603 | XSerializeEngine(const XSerializeEngine&);
|
---|
604 | XSerializeEngine& operator=(const XSerializeEngine&);
|
---|
605 |
|
---|
606 | /***
|
---|
607 | *
|
---|
608 | * Store Pool Opertions
|
---|
609 | *
|
---|
610 | ***/
|
---|
611 | XSerializedObjectId_t lookupStorePool(void* const objectPtr) const;
|
---|
612 | void addStorePool(void* const objectPtr);
|
---|
613 |
|
---|
614 | /***
|
---|
615 | *
|
---|
616 | * Load Pool Opertions
|
---|
617 | *
|
---|
618 | ***/
|
---|
619 | XSerializable* lookupLoadPool(XSerializedObjectId_t objectTag) const;
|
---|
620 | void addLoadPool(void* const objectPtr);
|
---|
621 |
|
---|
622 | /***
|
---|
623 | *
|
---|
624 | * Intenal Buffer Operations
|
---|
625 | *
|
---|
626 | ***/
|
---|
627 | inline void checkAndFillBuffer(int bytesNeedToRead);
|
---|
628 |
|
---|
629 | inline void checkAndFlushBuffer(int bytesNeedToWrite);
|
---|
630 |
|
---|
631 | void fillBuffer();
|
---|
632 |
|
---|
633 | void flushBuffer();
|
---|
634 |
|
---|
635 | void pumpCount();
|
---|
636 |
|
---|
637 | /***
|
---|
638 | *
|
---|
639 | * Helper
|
---|
640 | *
|
---|
641 | ***/
|
---|
642 | inline void ensureStoring() const;
|
---|
643 |
|
---|
644 | inline void ensureLoading() const;
|
---|
645 |
|
---|
646 | inline void ensureStoreBuffer() const;
|
---|
647 |
|
---|
648 | inline void ensureLoadBuffer() const;
|
---|
649 |
|
---|
650 | inline void ensurePointer(void* const) const;
|
---|
651 |
|
---|
652 | inline void ensureBufferLen(int bufferLen) const;
|
---|
653 |
|
---|
654 | inline void Assert(bool toEval
|
---|
655 | , const XMLExcepts::Codes toThrow) const;
|
---|
656 |
|
---|
657 | inline size_t allignAdjust() const;
|
---|
658 |
|
---|
659 | inline void allignBufCur();
|
---|
660 |
|
---|
661 | // Make XTemplateSerializer friend of XSerializeEngine so that
|
---|
662 | // we can call lookupStorePool and lookupLoadPool in the case of
|
---|
663 | // annotations.
|
---|
664 | friend class XTemplateSerializer;
|
---|
665 |
|
---|
666 | // -------------------------------------------------------------------------------
|
---|
667 | // data
|
---|
668 | //
|
---|
669 | // fStoreLoad:
|
---|
670 | // Indicator: storing(serialization) or loading(de-serialization)
|
---|
671 | //
|
---|
672 | // fGrammarPool:
|
---|
673 | // Thw owning GrammarPool which instantiate this SerializeEngine
|
---|
674 | // instance
|
---|
675 | //
|
---|
676 | // fInputStream:
|
---|
677 | // Binary stream to read from (de-serialization), provided
|
---|
678 | // by client application, not owned.
|
---|
679 | //
|
---|
680 | // fOutputStream:
|
---|
681 | // Binary stream to write to (serialization), provided
|
---|
682 | // by client application, not owned.
|
---|
683 | //
|
---|
684 | // fBufSize:
|
---|
685 | // The size of the internal buffer
|
---|
686 | //
|
---|
687 | // fBufStart/fBufEnd:
|
---|
688 | //
|
---|
689 | // The internal buffer.
|
---|
690 | // fBufEnd:
|
---|
691 | // one beyond the last valid cell
|
---|
692 | // fBufEnd === (fBufStart + fBufSize)
|
---|
693 | //
|
---|
694 | // fBufCur:
|
---|
695 | // The cursor of the buffer
|
---|
696 | //
|
---|
697 | // fBufLoadMax:
|
---|
698 | // Indicating the end of the valid content in the buffer
|
---|
699 | //
|
---|
700 | // fStorePool:
|
---|
701 | // Object collection for storing
|
---|
702 | //
|
---|
703 | // fLoadPool:
|
---|
704 | // Object collection for loading
|
---|
705 | //
|
---|
706 | // fMapCount:
|
---|
707 | // -------------------------------------------------------------------------------
|
---|
708 | const short fStoreLoad;
|
---|
709 | XMLGrammarPool* const fGrammarPool;
|
---|
710 | BinInputStream* const fInputStream;
|
---|
711 | BinOutputStream* const fOutputStream;
|
---|
712 |
|
---|
713 | //buffer
|
---|
714 | const unsigned long fBufSize;
|
---|
715 | XMLByte* const fBufStart;
|
---|
716 | XMLByte* const fBufEnd;
|
---|
717 | XMLByte* fBufCur;
|
---|
718 | XMLByte* fBufLoadMax;
|
---|
719 |
|
---|
720 | /***
|
---|
721 | * Map for storing object
|
---|
722 | *
|
---|
723 | * key: XSerializable*
|
---|
724 | * XProtoType*
|
---|
725 | *
|
---|
726 | * value: XMLInteger*, owned
|
---|
727 | *
|
---|
728 | ***/
|
---|
729 | RefHashTableOf<XSerializedObjectId>* fStorePool;
|
---|
730 |
|
---|
731 | /***
|
---|
732 | * Vector for loading object, objects are NOT owned
|
---|
733 | *
|
---|
734 | * data: XSerializable*
|
---|
735 | * XProtoType*
|
---|
736 | *
|
---|
737 | ***/
|
---|
738 | ValueVectorOf<void*>* fLoadPool;
|
---|
739 |
|
---|
740 | /***
|
---|
741 | * object counter
|
---|
742 | ***/
|
---|
743 | XSerializedObjectId_t fObjectCount;
|
---|
744 | };
|
---|
745 |
|
---|
746 | inline bool XSerializeEngine::isStoring() const
|
---|
747 | {
|
---|
748 | return (fStoreLoad == mode_Store);
|
---|
749 | }
|
---|
750 |
|
---|
751 | inline bool XSerializeEngine::isLoading() const
|
---|
752 | {
|
---|
753 | return (fStoreLoad == mode_Load);
|
---|
754 | }
|
---|
755 |
|
---|
756 | inline XSerializeEngine& operator<<(XSerializeEngine& serEng
|
---|
757 | , XSerializable* const serObj)
|
---|
758 | {
|
---|
759 | serEng.write(serObj);
|
---|
760 | return serEng;
|
---|
761 | }
|
---|
762 |
|
---|
763 | inline void XSerializeEngine::ensureStoring() const
|
---|
764 | {
|
---|
765 | Assert(isStoring(), XMLExcepts::XSer_Storing_Violation);
|
---|
766 | }
|
---|
767 |
|
---|
768 | inline void XSerializeEngine::ensureLoading() const
|
---|
769 | {
|
---|
770 | Assert(isLoading(), XMLExcepts::XSer_Loading_Violation);
|
---|
771 | }
|
---|
772 |
|
---|
773 |
|
---|
774 |
|
---|
775 | inline void XSerializeEngine::Assert(bool toEval
|
---|
776 | , const XMLExcepts::Codes toThrow) const
|
---|
777 | {
|
---|
778 | if (!toEval)
|
---|
779 | {
|
---|
780 | ThrowXMLwithMemMgr(XSerializationException, toThrow, getMemoryManager());
|
---|
781 | }
|
---|
782 |
|
---|
783 | }
|
---|
784 |
|
---|
785 | // For the following built-in datatype, we assume
|
---|
786 | // the same allignment requirement
|
---|
787 | //
|
---|
788 | // short unsigned short
|
---|
789 | // int unsigned long
|
---|
790 | // long unsigned long
|
---|
791 | // float
|
---|
792 | // double
|
---|
793 | //
|
---|
794 | // Based on the current position (fBufCur), calculated the needed size
|
---|
795 | // to read/write
|
---|
796 | //
|
---|
797 | inline size_t XSerializeEngine::allignAdjust() const
|
---|
798 | {
|
---|
799 | #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
|
---|
800 | size_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
|
---|
801 | #else
|
---|
802 | size_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
|
---|
803 | #endif
|
---|
804 |
|
---|
805 | size_t remainder = (size_t) fBufCur % alignment;
|
---|
806 | return (remainder == 0) ? 0 : (alignment - remainder);
|
---|
807 | }
|
---|
808 |
|
---|
809 | // Adjust the fBufCur
|
---|
810 | inline void XSerializeEngine::allignBufCur()
|
---|
811 | {
|
---|
812 | fBufCur+=allignAdjust();
|
---|
813 | }
|
---|
814 |
|
---|
815 | inline void XSerializeEngine::readString(XMLCh*& toRead
|
---|
816 | , int& bufferLen)
|
---|
817 | {
|
---|
818 | int dummyDataLen;
|
---|
819 | readString(toRead, bufferLen, dummyDataLen);
|
---|
820 | }
|
---|
821 |
|
---|
822 | inline void XSerializeEngine::readString(XMLCh*& toRead)
|
---|
823 | {
|
---|
824 | int dummyBufferLen;
|
---|
825 | int dummyDataLen;
|
---|
826 | readString(toRead, dummyBufferLen, dummyDataLen);
|
---|
827 | }
|
---|
828 |
|
---|
829 | inline void XSerializeEngine::readString(XMLByte*& toRead
|
---|
830 | , int& bufferLen)
|
---|
831 | {
|
---|
832 | int dummyDataLen;
|
---|
833 | readString(toRead, bufferLen, dummyDataLen);
|
---|
834 | }
|
---|
835 |
|
---|
836 | inline void XSerializeEngine::readString(XMLByte*& toRead)
|
---|
837 | {
|
---|
838 | int dummyBufferLen;
|
---|
839 | int dummyDataLen;
|
---|
840 | readString(toRead, dummyBufferLen, dummyDataLen);
|
---|
841 | }
|
---|
842 |
|
---|
843 | /***
|
---|
844 | * Ought to be nested class
|
---|
845 | ***/
|
---|
846 | class XSerializedObjectId : public XMemory
|
---|
847 | {
|
---|
848 | public:
|
---|
849 |
|
---|
850 | ~XSerializedObjectId(){};
|
---|
851 |
|
---|
852 | private:
|
---|
853 |
|
---|
854 | inline XSerializedObjectId(XSerializeEngine::XSerializedObjectId_t val):
|
---|
855 | fData(val) { };
|
---|
856 |
|
---|
857 | inline XSerializeEngine::XSerializedObjectId_t getValue() const {return fData; };
|
---|
858 |
|
---|
859 | friend class XSerializeEngine;
|
---|
860 |
|
---|
861 | private:
|
---|
862 | // -----------------------------------------------------------------------
|
---|
863 | // Unimplemented constructors and operators
|
---|
864 | // -----------------------------------------------------------------------
|
---|
865 | XSerializedObjectId();
|
---|
866 | XSerializedObjectId(const XSerializedObjectId&);
|
---|
867 | XSerializedObjectId& operator=(const XSerializedObjectId&);
|
---|
868 |
|
---|
869 | XSerializeEngine::XSerializedObjectId_t fData;
|
---|
870 |
|
---|
871 | };
|
---|
872 |
|
---|
873 |
|
---|
874 | XERCES_CPP_NAMESPACE_END
|
---|
875 |
|
---|
876 | #endif
|
---|