Logo ROOT   6.14/05
Reference Guide
TBufferText.h
Go to the documentation of this file.
1 // $Id$
2 // Author: Sergey Linev 21.12.2017
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TBufferText
13 #define ROOT_TBufferText
14 
15 #include "TBufferIO.h"
16 #include "TString.h"
17 
18 class TStreamerBase;
19 class TExMap;
20 
21 class TBufferText : public TBufferIO {
22 
23 protected:
24  TBufferText();
25  TBufferText(TBuffer::EMode mode, TObject *parent = nullptr);
26 
27 public:
28  virtual ~TBufferText();
29 
30  // virtual TBuffer methods, which are generic for all text-based streamers
31 
32  virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass = nullptr);
33  virtual void StreamObject(void *obj, const char *className, const TClass *onFileClass = nullptr);
34  virtual void StreamObject(TObject *obj);
36 
37  virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object);
38  virtual Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection,
39  void *end_collection);
40  virtual Int_t
41  ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection);
42 
43  virtual void ReadFloat16(Float_t *f, TStreamerElement *ele = nullptr);
44  virtual void WriteFloat16(Float_t *f, TStreamerElement *ele = nullptr);
45  virtual void ReadDouble32(Double_t *d, TStreamerElement *ele = nullptr);
46  virtual void WriteDouble32(Double_t *d, TStreamerElement *ele = nullptr);
47  virtual void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue);
48  virtual void ReadWithNbits(Float_t *ptr, Int_t nbits);
49  virtual void ReadWithFactor(Double_t *ptr, Double_t factor, Double_t minvalue);
50  virtual void ReadWithNbits(Double_t *ptr, Int_t nbits);
51 
52  virtual Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele = nullptr);
53  virtual Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele = nullptr);
54 
55  virtual Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele = nullptr);
56  virtual Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele = nullptr);
57 
58  virtual void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele = nullptr);
59  virtual void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele = nullptr);
60  virtual void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue);
61  virtual void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits);
62  virtual void ReadFastArrayWithFactor(Double_t *ptr, Int_t n, Double_t factor, Double_t minvalue);
63  virtual void ReadFastArrayWithNbits(Double_t *ptr, Int_t n, Int_t nbits);
64 
65  virtual void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele = nullptr);
66  virtual void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele = nullptr);
67 
68  virtual void WriteFastArrayFloat16(const Float_t *d, Int_t n, TStreamerElement *ele = nullptr);
69  virtual void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele = nullptr);
70 
71  // Utilities for TClass
72  virtual Int_t ReadClassBuffer(const TClass * /*cl*/, void * /*pointer*/, const TClass * /*onfile_class*/ = nullptr);
73  virtual Int_t ReadClassBuffer(const TClass * /*cl*/, void * /*pointer*/, Int_t /*version*/, UInt_t /*start*/,
74  UInt_t /*count*/, const TClass * /*onfile_class*/ = nullptr);
75  virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer);
76 
77  // virtual abstract TBuffer methods, which are not used in text streaming
78 
79  virtual Int_t CheckByteCount(UInt_t /* startpos */, UInt_t /* bcnt */, const TClass * /* clss */) { return 0; }
80  virtual Int_t CheckByteCount(UInt_t /* startpos */, UInt_t /* bcnt */, const char * /* classname */) { return 0; }
81  virtual void SetByteCount(UInt_t /* cntpos */, Bool_t /* packInVersion */ = kFALSE) {}
82  virtual void SkipVersion(const TClass *cl = nullptr);
83  virtual Version_t ReadVersionNoCheckSum(UInt_t *, UInt_t *) { return 0; }
84 
85  virtual Int_t ReadBuf(void * /*buf*/, Int_t /*max*/)
86  {
87  Error("ReadBuf", "useless in text streamers");
88  return 0;
89  }
90  virtual void WriteBuf(const void * /*buf*/, Int_t /*max*/) { Error("WriteBuf", "useless in text streamers"); }
91 
92  virtual char *ReadString(char * /*s*/, Int_t /*max*/)
93  {
94  Error("ReadString", "useless");
95  return nullptr;
96  }
97  virtual void WriteString(const char * /*s*/) { Error("WriteString", "useless"); }
98 
99  virtual Version_t ReadVersionForMemberWise(const TClass * /*cl*/ = nullptr)
100  {
101  Error("ReadVersionForMemberWise", "not defined in text-based streamers");
102  return 0;
103  }
104  virtual UInt_t WriteVersionMemberWise(const TClass * /*cl*/, Bool_t /*useBcnt*/ = kFALSE)
105  {
106  Error("WriteVersionMemberWise", "not defined in text-based streamers");
107  return 0;
108  }
109 
110  virtual TObject *ReadObject(const TClass * /*cl*/)
111  {
112  Error("ReadObject", "not yet implemented for text-based streamers");
113  return nullptr;
114  }
115 
116  // Utilities for TClass
117  virtual Int_t ReadClassEmulated(const TClass * /*cl*/, void * /*object*/, const TClass * /*onfile_class*/ = nullptr)
118  {
119  Error("ReadClassEmulated", "not defined in text-based streamers");
120  return 0;
121  }
122 
123  virtual void WriteBaseClass(void *start, TStreamerBase *elem);
124 
125  virtual void ReadBaseClass(void *start, TStreamerBase *elem);
126 
127  static void SetFloatFormat(const char *fmt = "%e");
128  static const char *GetFloatFormat();
129  static void SetDoubleFormat(const char *fmt = "%.14e");
130  static const char *GetDoubleFormat();
131 
132  static void CompactFloatString(char *buf, unsigned len);
133  static const char *ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize = kFALSE);
134  static const char *ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize = kFALSE);
135 
136 protected:
137  static const char *fgFloatFmt; ///<! printf argument for floats, either "%f" or "%e" or "%10f" and so on
138  static const char *fgDoubleFmt; ///<! printf argument for doubles, either "%f" or "%e" or "%10f" and so on
139 
140  ClassDef(TBufferText, 0); // a TBuffer subclass for all text-based streamers
141 };
142 
143 #endif
virtual Int_t ReadClassEmulated(const TClass *, void *, const TClass *=nullptr)
Definition: TBufferText.h:117
static const char * ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
short Version_t
Definition: RtypesCore.h:61
virtual void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=nullptr)
Write array of Float16_t to buffer.
float Float_t
Definition: RtypesCore.h:53
virtual void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue)
read array of Float16_t from buffer
virtual Version_t ReadVersionNoCheckSum(UInt_t *, UInt_t *)
Definition: TBufferText.h:83
virtual void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr)
Write array of Double32_t to buffer.
virtual void WriteDouble32(Double_t *d, TStreamerElement *ele=nullptr)
write a Double32_t to the buffer
virtual UInt_t WriteVersionMemberWise(const TClass *, Bool_t=kFALSE)
Definition: TBufferText.h:104
static void SetDoubleFormat(const char *fmt="%.14e")
set printf format for double members, default "%.14e" use it after SetFloatFormat, which also overwrites format for doubles
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
virtual void WriteString(const char *)
Definition: TBufferText.h:97
bool Bool_t
Definition: RtypesCore.h:59
virtual Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=nullptr)
Read array of Double32_t from buffer.
virtual Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele=nullptr)
Read array of Double32_t from buffer.
virtual ~TBufferText()
destructor
Definition: TBufferText.cxx:61
virtual Int_t CheckByteCount(UInt_t, UInt_t, const TClass *)
Definition: TBufferText.h:79
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=nullptr)
stream object to/from buffer
virtual void WriteFloat16(Float_t *f, TStreamerElement *ele=nullptr)
write a Float16_t to the buffer
virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object)
Read one collection of objects from the buffer using the StreamerInfoLoopAction.
Definition: TBufferText.cxx:69
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual Int_t ReadBuf(void *, Int_t)
Definition: TBufferText.h:85
virtual void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=nullptr)
read array of Float16_t from buffer
virtual void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr)
Write array of Double32_t to buffer.
virtual void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits)
read array of Float16_t from buffer
static const char * fgFloatFmt
! printf argument for floats, either "%f" or "%e" or "%10f" and so on
Definition: TBufferText.h:137
virtual Version_t ReadVersionForMemberWise(const TClass *=nullptr)
Definition: TBufferText.h:99
SVector< double, 2 > v
Definition: Dict.h:5
virtual void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue)
Read a Double32_t from the buffer when the factor and minimun value have been specified see comments ...
TBufferText()
Default constructor.
Definition: TBufferText.cxx:43
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual void SetByteCount(UInt_t, Bool_t=kFALSE)
Definition: TBufferText.h:81
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)
Function called by the Streamer functions to serialize object at p to buffer b.
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
virtual Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection)
Read one collection of objects from the buffer using the StreamerInfoLoopAction.
static const char * ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=0)=0
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define d(i)
Definition: RSha256.hxx:102
Base class for text-based streamers like TBufferJSON or TBufferXML Special actions list will use meth...
Definition: TBufferText.h:21
double Double_t
Definition: RtypesCore.h:55
virtual void ReadWithNbits(Float_t *ptr, Int_t nbits)
Read a Float16_t from the buffer when the number of bits is specified (explicitly or not) see comment...
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e" to change format only for doubles...
virtual void ReadDouble32(Double_t *d, TStreamerElement *ele=nullptr)
read a Double32_t from the buffer
virtual Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=nullptr)
Read array of Float16_t from buffer.
static const char * GetDoubleFormat()
return current printf format for double members, default "%.14e"
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void WriteBaseClass(void *start, TStreamerBase *elem)
Write data of base class.
static const char * fgDoubleFmt
! printf argument for doubles, either "%f" or "%e" or "%10f" and so on
Definition: TBufferText.h:138
Direct subclass of TBuffer, implements common methods for TBufferFile and TBufferText classes...
Definition: TBufferIO.h:30
virtual void WriteBuf(const void *, Int_t)
Definition: TBufferText.h:90
virtual Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele=nullptr)
Read array of Float16_t from buffer.
static const char * GetFloatFormat()
return current printf format for float members, default "%e"
static void CompactFloatString(char *buf, unsigned len)
method compress float string, excluding exp and/or move float point
virtual void ReadBaseClass(void *start, TStreamerBase *elem)
Read data of base class.
virtual void SkipVersion(const TClass *cl=nullptr)
Skip class version from I/O buffer.
virtual Int_t CheckByteCount(UInt_t, UInt_t, const char *)
Definition: TBufferText.h:80
virtual void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=nullptr)
read array of Double32_t from buffer
virtual TObject * ReadObject(const TClass *)
Definition: TBufferText.h:110
virtual char * ReadString(char *, Int_t)
Definition: TBufferText.h:92
virtual void WriteFastArrayFloat16(const Float_t *d, Int_t n, TStreamerElement *ele=nullptr)
Write array of Float16_t to buffer.
const Int_t n
Definition: legend1.C:16
virtual Int_t ReadClassBuffer(const TClass *, void *, const TClass *=nullptr)
Deserialize information from a buffer into an object.
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33
virtual void ReadFloat16(Float_t *f, TStreamerElement *ele=nullptr)
read a Float16_t from the buffer