Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TBufferSQL2.h
Go to the documentation of this file.
1 // @(#)root/sql
2 // Author: Sergey Linev 20/11/2005
3 
4 #ifndef ROOT_TBufferSQL2
5 #define ROOT_TBufferSQL2
6 
7 #include "TBufferText.h"
8 #include "TString.h"
9 #include "TObjArray.h"
10 
11 class TMap;
12 class TExMap;
13 class TVirtualStreamerInfo;
14 class TStreamerElement;
15 class TObjArray;
16 class TMemberStreamer;
17 
18 class TSQLStackObj;
19 class TSQLServer;
20 class TSQLResult;
21 class TSQLRow;
22 class TSQLFile;
23 class TSQLStructure;
24 class TSQLObjectData;
25 class TSQLClassInfo;
26 
27 class TBufferSQL2 final : public TBufferText {
28 
29  friend class TSQLStructure;
30 
31 protected:
32  TSQLFile *fSQL; ///<! instance of TSQLFile
33  Int_t fIOVersion; ///<! I/O version from TSQLFile
34  TSQLStructure *fStructure; ///<! structures, created by object storing
35  TSQLStructure *fStk; ///<! pointer on current active structure (stack head)
36  TString fReadBuffer; ///<! Buffer for read value
37  Int_t fErrorFlag; ///<! Error id value
38  Int_t fCompressLevel; ///<! compress level used to minimize size of data in database
39  Int_t fReadVersionBuffer; ///<! buffer, used to by ReadVersion method
40  Long64_t fObjIdCounter; ///<! counter of objects id
41  Bool_t fIgnoreVerification; ///<! ignore verification of names
42  TSQLObjectData *fCurrentData; ///<!
43  TObjArray *fObjectsInfos; ///<! array of objects info for selected key
44  Long64_t fFirstObjId; ///<! id of first object to be read from the database
45  Long64_t fLastObjId; ///<! id of last object correspond to this key
46  TMap *fPoolsMap; ///<! map of pools with data from different tables
47 
48  // TBufferSQL2 objects cannot be copied or assigned
49  TBufferSQL2(const TBufferSQL2 &); // not implemented
50  void operator=(const TBufferSQL2 &); // not implemented
51 
52  TBufferSQL2();
53 
54  // redefined protected virtual functions
55 
56  void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse) final;
57 
58  // end redefined protected virtual functions
59 
60  TSQLStructure *PushStack();
61  TSQLStructure *PopStack();
62  TSQLStructure *Stack(Int_t depth = 0);
63 
64  void WorkWithClass(const char *classname, Version_t classversion);
65  void WorkWithElement(TStreamerElement *elem, Int_t comp_type);
66 
67  Int_t SqlReadArraySize();
68  Bool_t SqlObjectInfo(Long64_t objid, TString &clname, Version_t &version);
69  TSQLObjectData *SqlObjectData(Long64_t objid, TSQLClassInfo *sqlinfo);
70 
71  Bool_t SqlWriteBasic(Char_t value);
72  Bool_t SqlWriteBasic(Short_t value);
73  Bool_t SqlWriteBasic(Int_t value);
74  Bool_t SqlWriteBasic(Long_t value);
75  Bool_t SqlWriteBasic(Long64_t value);
76  Bool_t SqlWriteBasic(Float_t value);
77  Bool_t SqlWriteBasic(Double_t value);
78  Bool_t SqlWriteBasic(Bool_t value);
79  Bool_t SqlWriteBasic(UChar_t value);
80  Bool_t SqlWriteBasic(UShort_t value);
81  Bool_t SqlWriteBasic(UInt_t value);
82  Bool_t SqlWriteBasic(ULong_t value);
83  Bool_t SqlWriteBasic(ULong64_t value);
84  Bool_t SqlWriteValue(const char *value, const char *tname);
85 
86  void SqlReadBasic(Char_t &value);
87  void SqlReadBasic(Short_t &value);
88  void SqlReadBasic(Int_t &value);
89  void SqlReadBasic(Long_t &value);
90  void SqlReadBasic(Long64_t &value);
91  void SqlReadBasic(Float_t &value);
92  void SqlReadBasic(Double_t &value);
93  void SqlReadBasic(Bool_t &value);
94  void SqlReadBasic(UChar_t &value);
95  void SqlReadBasic(UShort_t &value);
96  void SqlReadBasic(UInt_t &value);
97  void SqlReadBasic(ULong_t &value);
98  void SqlReadBasic(ULong64_t &value);
99  const char *SqlReadValue(const char *tname);
100  const char *SqlReadCharStarValue();
101 
102  Int_t SqlWriteObject(const void *obj, const TClass *objClass, Bool_t cacheReuse, TMemberStreamer *streamer = nullptr,
103  Int_t streamer_index = 0);
104  void *SqlReadObject(void *obj, TClass **cl = nullptr, TMemberStreamer *streamer = nullptr, Int_t streamer_index = 0,
105  const TClass *onFileClass = nullptr);
106  void *SqlReadObjectDirect(void *obj, TClass **cl, Long64_t objid, TMemberStreamer *streamer = nullptr,
107  Int_t streamer_index = 0, const TClass *onFileClass = nullptr);
108 
109  void StreamObjectExtra(void *obj, TMemberStreamer *streamer, const TClass *cl, Int_t n = 0,
110  const TClass *onFileClass = nullptr);
111 
112  template <typename T>
113  R__ALWAYS_INLINE void SqlReadArrayContent(T *arr, Int_t arrsize, Bool_t withsize);
114 
115  template <typename T>
116  R__ALWAYS_INLINE Int_t SqlReadArray(T *&arr, Bool_t is_static = kFALSE);
117 
118  template <typename T>
119  R__ALWAYS_INLINE void SqlReadFastArray(T *arr, Int_t arrsize);
120 
121  template <typename T>
122  R__ALWAYS_INLINE void SqlWriteArray(T *arr, Int_t arrsize, Bool_t withsize = kFALSE);
123 
124 public:
125  TBufferSQL2(TBuffer::EMode mode, TSQLFile *file = nullptr);
126  virtual ~TBufferSQL2();
127 
128  void SetCompressionLevel(int level) { fCompressLevel = level; }
129 
130  TSQLStructure *GetStructure() const { return fStructure; }
131 
132  Int_t GetErrorFlag() const { return fErrorFlag; }
133 
134  void SetIgnoreVerification() { fIgnoreVerification = kTRUE; }
135 
136  TSQLStructure *SqlWriteAny(const void *obj, const TClass *cl, Long64_t objid);
137 
138  void *SqlReadAny(Long64_t keyid, Long64_t objid, TClass **cl, void *obj = nullptr);
139 
140  // suppress class writing/reading
141 
142  TClass *ReadClass(const TClass *cl = nullptr, UInt_t *objTag = nullptr) final;
143  void WriteClass(const TClass *cl) final;
144 
145  // redefined virtual functions of TBuffer
146 
147  Version_t ReadVersion(UInt_t *start = nullptr, UInt_t *bcnt = nullptr, const TClass *cl = nullptr) final;
148  UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt = kFALSE) final;
149 
150  void *ReadObjectAny(const TClass *clCast) final;
151  void SkipObjectAny() final;
152 
153  void IncrementLevel(TVirtualStreamerInfo *) final;
154  void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type) final;
155  void DecrementLevel(TVirtualStreamerInfo *) final;
156 
157  void ClassBegin(const TClass *, Version_t = -1) final;
158  void ClassEnd(const TClass *) final;
159  void ClassMember(const char *name, const char *typeName = 0, Int_t arrsize1 = -1, Int_t arrsize2 = -1) final;
160 
161  Int_t ReadArray(Bool_t *&b) final;
162  Int_t ReadArray(Char_t *&c) final;
163  Int_t ReadArray(UChar_t *&c) final;
164  Int_t ReadArray(Short_t *&h) final;
165  Int_t ReadArray(UShort_t *&h) final;
166  Int_t ReadArray(Int_t *&i) final;
167  Int_t ReadArray(UInt_t *&i) final;
168  Int_t ReadArray(Long_t *&l) final;
169  Int_t ReadArray(ULong_t *&l) final;
170  Int_t ReadArray(Long64_t *&l) final;
171  Int_t ReadArray(ULong64_t *&l) final;
172  Int_t ReadArray(Float_t *&f) final;
173  Int_t ReadArray(Double_t *&d) final;
174 
175  Int_t ReadStaticArray(Bool_t *b) final;
176  Int_t ReadStaticArray(Char_t *c) final;
177  Int_t ReadStaticArray(UChar_t *c) final;
178  Int_t ReadStaticArray(Short_t *h) final;
179  Int_t ReadStaticArray(UShort_t *h) final;
180  Int_t ReadStaticArray(Int_t *i) final;
181  Int_t ReadStaticArray(UInt_t *i) final;
182  Int_t ReadStaticArray(Long_t *l) final;
183  Int_t ReadStaticArray(ULong_t *l) final;
184  Int_t ReadStaticArray(Long64_t *l) final;
185  Int_t ReadStaticArray(ULong64_t *l) final;
186  Int_t ReadStaticArray(Float_t *f) final;
187  Int_t ReadStaticArray(Double_t *d) final;
188 
189  void ReadFastArray(Bool_t *b, Int_t n) final;
190  void ReadFastArray(Char_t *c, Int_t n) final;
191  void ReadFastArray(UChar_t *c, Int_t n) final;
192  void ReadFastArray(Short_t *h, Int_t n) final;
193  void ReadFastArray(UShort_t *h, Int_t n) final;
194  void ReadFastArray(Int_t *i, Int_t n) final;
195  void ReadFastArray(UInt_t *i, Int_t n) final;
196  void ReadFastArray(Long_t *l, Int_t n) final;
197  void ReadFastArray(ULong_t *l, Int_t n) final;
198  void ReadFastArray(Long64_t *l, Int_t n) final;
199  void ReadFastArray(ULong64_t *l, Int_t n) final;
200  void ReadFastArray(Float_t *f, Int_t n) final;
201  void ReadFastArray(Double_t *d, Int_t n) final;
202  void ReadFastArrayString(Char_t *c, Int_t n) final;
203  void ReadFastArray(void *start, const TClass *cl, Int_t n = 1, TMemberStreamer *s = nullptr,
204  const TClass *onFileClass = nullptr) final;
205  void ReadFastArray(void **startp, const TClass *cl, Int_t n = 1, Bool_t isPreAlloc = kFALSE,
206  TMemberStreamer *s = nullptr, const TClass *onFileClass = nullptr) final;
207 
208  void WriteArray(const Bool_t *b, Int_t n) final;
209  void WriteArray(const Char_t *c, Int_t n) final;
210  void WriteArray(const UChar_t *c, Int_t n) final;
211  void WriteArray(const Short_t *h, Int_t n) final;
212  void WriteArray(const UShort_t *h, Int_t n) final;
213  void WriteArray(const Int_t *i, Int_t n) final;
214  void WriteArray(const UInt_t *i, Int_t n) final;
215  void WriteArray(const Long_t *l, Int_t n) final;
216  void WriteArray(const ULong_t *l, Int_t n) final;
217  void WriteArray(const Long64_t *l, Int_t n) final;
218  void WriteArray(const ULong64_t *l, Int_t n) final;
219  void WriteArray(const Float_t *f, Int_t n) final;
220  void WriteArray(const Double_t *d, Int_t n) final;
221 
222  void WriteFastArray(const Bool_t *b, Int_t n) final;
223  void WriteFastArray(const Char_t *c, Int_t n) final;
224  void WriteFastArray(const UChar_t *c, Int_t n) final;
225  void WriteFastArray(const Short_t *h, Int_t n) final;
226  void WriteFastArray(const UShort_t *h, Int_t n) final;
227  void WriteFastArray(const Int_t *i, Int_t n) final;
228  void WriteFastArray(const UInt_t *i, Int_t n) final;
229  void WriteFastArray(const Long_t *l, Int_t n) final;
230  void WriteFastArray(const ULong_t *l, Int_t n) final;
231  void WriteFastArray(const Long64_t *l, Int_t n) final;
232  void WriteFastArray(const ULong64_t *l, Int_t n) final;
233  void WriteFastArray(const Float_t *f, Int_t n) final;
234  void WriteFastArray(const Double_t *d, Int_t n) final;
235  void WriteFastArrayString(const Char_t *c, Int_t n) final;
236  void WriteFastArray(void *start, const TClass *cl, Int_t n = 1, TMemberStreamer *s = nullptr) final;
237  Int_t WriteFastArray(void **startp, const TClass *cl, Int_t n = 1, Bool_t isPreAlloc = kFALSE,
238  TMemberStreamer *s = nullptr) final;
239 
240  void StreamObject(void *obj, const TClass *cl, const TClass *onFileClass = nullptr) final;
241  using TBufferText::StreamObject;
242 
243  void ReadBool(Bool_t &b) final;
244  void ReadChar(Char_t &c) final;
245  void ReadUChar(UChar_t &c) final;
246  void ReadShort(Short_t &s) final;
247  void ReadUShort(UShort_t &s) final;
248  void ReadInt(Int_t &i) final;
249  void ReadUInt(UInt_t &i) final;
250  void ReadLong(Long_t &l) final;
251  void ReadULong(ULong_t &l) final;
252  void ReadLong64(Long64_t &l) final;
253  void ReadULong64(ULong64_t &l) final;
254  void ReadFloat(Float_t &f) final;
255  void ReadDouble(Double_t &d) final;
256  void ReadCharP(Char_t *c) final;
257  void ReadTString(TString &s) final;
258  void ReadStdString(std::string *s) final;
259  using TBuffer::ReadStdString;
260  void ReadCharStar(char *&s) final;
261 
262  void WriteBool(Bool_t b) final;
263  void WriteChar(Char_t c) final;
264  void WriteUChar(UChar_t c) final;
265  void WriteShort(Short_t s) final;
266  void WriteUShort(UShort_t s) final;
267  void WriteInt(Int_t i) final;
268  void WriteUInt(UInt_t i) final;
269  void WriteLong(Long_t l) final;
270  void WriteULong(ULong_t l) final;
271  void WriteLong64(Long64_t l) final;
272  void WriteULong64(ULong64_t l) final;
273  void WriteFloat(Float_t f) final;
274  void WriteDouble(Double_t d) final;
275  void WriteCharP(const Char_t *c) final;
276  void WriteTString(const TString &s) final;
277  void WriteStdString(const std::string *s) final;
278  using TBuffer::WriteStdString;
279  void WriteCharStar(char *s) final;
280 
281  TVirtualStreamerInfo *GetInfo() final;
282 
283  // end of redefined virtual functions
284 
285  ClassDefOverride(TBufferSQL2, 0); // a specialized TBuffer to convert data to SQL statements or read data from SQL tables
286 };
287 
288 #endif