File indexing completed on 2025-01-18 10:14:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #if !defined(XERCESC_INCLUDE_GUARD_XSERIALIZE_ENGINE_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XSERIALIZE_ENGINE_HPP
0024
0025 #include <xercesc/util/RefHashTableOf.hpp>
0026 #include <xercesc/util/ValueVectorOf.hpp>
0027 #include <xercesc/util/XMLExceptMsgs.hpp>
0028
0029 #include <xercesc/internal/XSerializationException.hpp>
0030
0031 XERCES_CPP_NAMESPACE_BEGIN
0032
0033 class XSerializable;
0034 class XProtoType;
0035 class MemoryManager;
0036 class XSerializedObjectId;
0037 class BinOutputStream;
0038 class BinInputStream;
0039 class XMLGrammarPool;
0040 class XMLGrammarPoolImpl;
0041 class XMLStringPool;
0042
0043 class XMLUTIL_EXPORT XSerializeEngine
0044 {
0045 public:
0046
0047 enum { mode_Store
0048 , mode_Load
0049 };
0050
0051
0052 static const bool toReadBufferLen;
0053
0054 typedef unsigned int XSerializedObjectId_t;
0055
0056
0057
0058
0059
0060
0061 ~XSerializeEngine();
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 XSerializeEngine(BinInputStream* inStream
0078 , XMLGrammarPool* const gramPool
0079 , XMLSize_t bufSize = 8192 );
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 XSerializeEngine(BinOutputStream* outStream
0097 , XMLGrammarPool* const gramPool
0098 , XMLSize_t bufSize = 8192 );
0099
0100
0101
0102
0103
0104
0105
0106
0107 void flush();
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 inline bool isStoring() const;
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 inline bool isLoading() const;
0128
0129
0130
0131
0132
0133
0134
0135
0136 XMLGrammarPool* getGrammarPool() const;
0137
0138
0139
0140
0141
0142
0143
0144
0145 XMLStringPool* getStringPool() const;
0146
0147
0148
0149
0150
0151
0152
0153
0154 MemoryManager* getMemoryManager() const;
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 inline unsigned int getStorerLevel() const;
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 void write(XSerializable* const objectToWrite);
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192 void write(XProtoType* const protoType);
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205 void write(const XMLByte* const toWrite
0206 , XMLSize_t writeLen);
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 void write(const XMLCh* const toWrite
0220 , XMLSize_t writeLen);
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237 void writeString(const XMLCh* const toWrite
0238 , const XMLSize_t bufferLen = 0
0239 , bool toWriteBufLen = false);
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256 void writeString(const XMLByte* const toWrite
0257 , const XMLSize_t bufferLen = 0
0258 , bool toWriteBufLen = false);
0259
0260 static const bool toWriteBufferLen;
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272 XSerializable* read(XProtoType* const protoType);
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287 bool read(XProtoType* const protoType
0288 , XSerializedObjectId_t* objTag);
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301 void read(XMLByte* const toRead
0302 , XMLSize_t readLen);
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315 void read(XMLCh* const toRead
0316 , XMLSize_t readLen);
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334 void readString(XMLCh*& toRead
0335 , XMLSize_t& bufferLen
0336 , XMLSize_t& dataLen
0337 , bool toReadBufLen = false);
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353 inline void readString(XMLCh*& toRead
0354 , XMLSize_t& bufferLen);
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366 inline void readString(XMLCh*& toRead);
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384 void readString(XMLByte*& toRead
0385 , XMLSize_t& bufferLen
0386 , XMLSize_t& dataLen
0387 , bool toReadBufLen = false);
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404 inline void readString(XMLByte*& toRead
0405 , XMLSize_t& bufferLen);
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423 inline void readString(XMLByte*& toRead);
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436 bool needToStoreObject(void* const templateObjectToWrite);
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449 bool needToLoadObject(void** templateObjectToRead);
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463 void registerObject(void* const templateObjectToRegister);
0464
0465
0466
0467
0468
0469
0470
0471 friend XSerializeEngine& operator<<(XSerializeEngine&
0472 , XSerializable* const );
0473
0474
0475
0476
0477
0478
0479
0480
0481 XSerializeEngine& operator<<(XMLByte);
0482 XSerializeEngine& operator<<(XMLCh);
0483
0484 XSerializeEngine& operator<<(char);
0485 XSerializeEngine& operator<<(short);
0486 XSerializeEngine& operator<<(int);
0487 XSerializeEngine& operator<<(unsigned int);
0488 XSerializeEngine& operator<<(long);
0489 XSerializeEngine& operator<<(unsigned long);
0490 XSerializeEngine& operator<<(float);
0491 XSerializeEngine& operator<<(double);
0492 XSerializeEngine& operator<<(bool);
0493
0494
0495
0496
0497 void writeSize (XMLSize_t);
0498 void writeInt64 (XMLInt64);
0499 void writeUInt64 (XMLUInt64);
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509 XSerializeEngine& operator>>(XMLByte&);
0510 XSerializeEngine& operator>>(XMLCh&);
0511
0512 XSerializeEngine& operator>>(char&);
0513 XSerializeEngine& operator>>(short&);
0514 XSerializeEngine& operator>>(int&);
0515 XSerializeEngine& operator>>(unsigned int&);
0516 XSerializeEngine& operator>>(long&);
0517 XSerializeEngine& operator>>(unsigned long&);
0518 XSerializeEngine& operator>>(float&);
0519 XSerializeEngine& operator>>(double&);
0520 XSerializeEngine& operator>>(bool&);
0521
0522 void readSize (XMLSize_t&);
0523 void readInt64 (XMLInt64&);
0524 void readUInt64 (XMLUInt64&);
0525
0526
0527
0528
0529
0530
0531 inline
0532 XMLSize_t getBufSize() const;
0533
0534 inline
0535 XMLSize_t getBufCur() const;
0536
0537 inline
0538 XMLSize_t getBufCurAccumulated() const;
0539
0540 inline
0541 unsigned long getBufCount() const;
0542
0543 void trace(char*) const;
0544
0545 private:
0546
0547
0548
0549 XSerializeEngine();
0550 XSerializeEngine(const XSerializeEngine&);
0551 XSerializeEngine& operator=(const XSerializeEngine&);
0552
0553
0554
0555
0556
0557
0558 XSerializedObjectId_t lookupStorePool(void* const objectPtr) const;
0559 void addStorePool(void* const objectPtr);
0560
0561
0562
0563
0564
0565
0566 XSerializable* lookupLoadPool(XSerializedObjectId_t objectTag) const;
0567 void addLoadPool(void* const objectPtr);
0568
0569
0570
0571
0572
0573
0574 inline void checkAndFillBuffer(XMLSize_t bytesNeedToRead);
0575
0576 inline void checkAndFlushBuffer(XMLSize_t bytesNeedToWrite);
0577
0578 void fillBuffer();
0579
0580 void flushBuffer();
0581
0582 void pumpCount();
0583
0584 inline void resetBuffer();
0585
0586
0587
0588
0589
0590
0591 inline void ensureStoring() const;
0592
0593 inline void ensureLoading() const;
0594
0595 inline void ensureStoreBuffer() const;
0596
0597 inline void ensureLoadBuffer() const;
0598
0599 inline void ensurePointer(void* const) const;
0600
0601 inline void Assert(bool toEval
0602 , const XMLExcepts::Codes toThrow) const;
0603
0604
0605 inline XMLSize_t calBytesNeeded(XMLSize_t) const;
0606
0607 inline XMLSize_t alignAdjust(XMLSize_t) const;
0608
0609 inline void alignBufCur(XMLSize_t);
0610
0611
0612
0613
0614 friend class XTemplateSerializer;
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664 const short fStoreLoad;
0665 unsigned int fStorerLevel;
0666
0667 XMLGrammarPool* const fGrammarPool;
0668 BinInputStream* const fInputStream;
0669 BinOutputStream* const fOutputStream;
0670
0671 unsigned long fBufCount;
0672
0673
0674 const XMLSize_t fBufSize;
0675 XMLByte* const fBufStart;
0676 XMLByte* const fBufEnd;
0677 XMLByte* fBufCur;
0678 XMLByte* fBufLoadMax;
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691 RefHashTableOf<XSerializedObjectId, PtrHasher>* fStorePool;
0692
0693
0694
0695
0696
0697
0698
0699
0700 ValueVectorOf<void*>* fLoadPool;
0701
0702
0703
0704
0705 XSerializedObjectId_t fObjectCount;
0706
0707
0708 friend class XMLGrammarPoolImpl;
0709 };
0710
0711 inline bool XSerializeEngine::isStoring() const
0712 {
0713 return (fStoreLoad == mode_Store);
0714 }
0715
0716 inline bool XSerializeEngine::isLoading() const
0717 {
0718 return (fStoreLoad == mode_Load);
0719 }
0720
0721 inline XSerializeEngine& operator<<(XSerializeEngine& serEng
0722 , XSerializable* const serObj)
0723 {
0724 serEng.write(serObj);
0725 return serEng;
0726 }
0727
0728 inline void XSerializeEngine::ensureStoring() const
0729 {
0730 Assert(isStoring(), XMLExcepts::XSer_Storing_Violation);
0731 }
0732
0733 inline void XSerializeEngine::ensureLoading() const
0734 {
0735 Assert(isLoading(), XMLExcepts::XSer_Loading_Violation);
0736 }
0737
0738
0739
0740 inline void XSerializeEngine::Assert(bool toEval
0741 , const XMLExcepts::Codes toThrow) const
0742 {
0743 if (!toEval)
0744 {
0745 ThrowXMLwithMemMgr(XSerializationException, toThrow, getMemoryManager());
0746 }
0747
0748 }
0749
0750 inline void XSerializeEngine::readString(XMLCh*& toRead
0751 , XMLSize_t& bufferLen)
0752 {
0753 XMLSize_t dummyDataLen;
0754 readString(toRead, bufferLen, dummyDataLen);
0755 }
0756
0757 inline void XSerializeEngine::readString(XMLCh*& toRead)
0758 {
0759 XMLSize_t dummyBufferLen;
0760 XMLSize_t dummyDataLen;
0761 readString(toRead, dummyBufferLen, dummyDataLen);
0762 }
0763
0764 inline void XSerializeEngine::readString(XMLByte*& toRead
0765 , XMLSize_t& bufferLen)
0766 {
0767 XMLSize_t dummyDataLen;
0768 readString(toRead, bufferLen, dummyDataLen);
0769 }
0770
0771 inline void XSerializeEngine::readString(XMLByte*& toRead)
0772 {
0773 XMLSize_t dummyBufferLen;
0774 XMLSize_t dummyDataLen;
0775 readString(toRead, dummyBufferLen, dummyDataLen);
0776 }
0777
0778 inline
0779 XMLSize_t XSerializeEngine::getBufSize() const
0780 {
0781 return fBufSize;
0782 }
0783
0784 inline
0785 XMLSize_t XSerializeEngine::getBufCur() const
0786 {
0787 return (fBufCur-fBufStart);
0788 }
0789
0790 inline
0791 XMLSize_t XSerializeEngine::getBufCurAccumulated() const
0792 {
0793 return (fBufCount - (isStoring() ? 0: 1)) * fBufSize + (fBufCur-fBufStart);
0794 }
0795
0796 inline
0797 unsigned long XSerializeEngine::getBufCount() const
0798 {
0799 return fBufCount;
0800 }
0801
0802 inline
0803 unsigned int XSerializeEngine::getStorerLevel() const
0804 {
0805 return fStorerLevel;
0806 }
0807
0808
0809
0810
0811 class XSerializedObjectId : public XMemory
0812 {
0813 public:
0814
0815 ~XSerializedObjectId(){};
0816
0817 private:
0818
0819 inline XSerializedObjectId(XSerializeEngine::XSerializedObjectId_t val):
0820 fData(val) { };
0821
0822 inline XSerializeEngine::XSerializedObjectId_t getValue() const {return fData; };
0823
0824 friend class XSerializeEngine;
0825
0826 private:
0827
0828
0829
0830 XSerializedObjectId();
0831 XSerializedObjectId(const XSerializedObjectId&);
0832 XSerializedObjectId& operator=(const XSerializedObjectId&);
0833
0834 XSerializeEngine::XSerializedObjectId_t fData;
0835
0836 };
0837
0838
0839 XERCES_CPP_NAMESPACE_END
0840
0841 #endif