Logo ROOT   6.21/01
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  void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass = nullptr) override;
33  void StreamObject(void *obj, const char *className, const TClass *onFileClass = nullptr) override;
34  void StreamObject(TObject *obj) override;
36 
37  Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object) final;
38  Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection,
39  void *end_collection) final;
40  Int_t
41  ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection) final;
42 
43  void ReadFloat16(Float_t *f, TStreamerElement *ele = nullptr) final;
44  void WriteFloat16(Float_t *f, TStreamerElement *ele = nullptr) final;
45  void ReadDouble32(Double_t *d, TStreamerElement *ele = nullptr) final;
46  void WriteDouble32(Double_t *d, TStreamerElement *ele = nullptr) final;
47  void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue) final;
48  void ReadWithNbits(Float_t *ptr, Int_t nbits) final;
49  void ReadWithFactor(Double_t *ptr, Double_t factor, Double_t minvalue) final;
50  void ReadWithNbits(Double_t *ptr, Int_t nbits) final;
51 
52  Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele = nullptr) override;
53  Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele = nullptr) override;
54 
55  Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele = nullptr) final;
57 
58  void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele = nullptr) final;
59  void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele = nullptr) final;
60  void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue) final;
61  void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits) final;
62  void ReadFastArrayWithFactor(Double_t *ptr, Int_t n, Double_t factor, Double_t minvalue) final;
63  void ReadFastArrayWithNbits(Double_t *ptr, Int_t n, Int_t nbits) final;
64 
65  void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele = nullptr) final;
66  void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele = nullptr) final;
67 
68  void WriteFastArrayFloat16(const Float_t *d, Int_t n, TStreamerElement *ele = nullptr) final;
69  void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele = nullptr) final;
70 
71  // Utilities for TClass
72  Int_t ReadClassBuffer(const TClass * /*cl*/, void * /*pointer*/, const TClass * /*onfile_class*/ = nullptr) override;
73  Int_t ReadClassBuffer(const TClass * /*cl*/, void * /*pointer*/, Int_t /*version*/, UInt_t /*start*/,
74  UInt_t /*count*/, const TClass * /*onfile_class*/ = nullptr) override;
75  Int_t WriteClassBuffer(const TClass *cl, void *pointer) override;
76 
77  // virtual abstract TBuffer methods, which are not used in text streaming
78 
79  Int_t CheckByteCount(UInt_t /* startpos */, UInt_t /* bcnt */, const TClass * /* clss */) final { return 0; }
80  Int_t CheckByteCount(UInt_t /* startpos */, UInt_t /* bcnt */, const char * /* classname */) final { return 0; }
81  void SetByteCount(UInt_t /* cntpos */, Bool_t /* packInVersion */ = kFALSE) final {}
82  void SkipVersion(const TClass *cl = nullptr) final;
83  Version_t ReadVersionNoCheckSum(UInt_t *, UInt_t *) final { return 0; }
84 
85  Int_t ReadBuf(void * /*buf*/, Int_t /*max*/) final
86  {
87  Error("ReadBuf", "useless in text streamers");
88  return 0;
89  }
90  void WriteBuf(const void * /*buf*/, Int_t /*max*/) final { Error("WriteBuf", "useless in text streamers"); }
91 
92  char *ReadString(char * /*s*/, Int_t /*max*/) final
93  {
94  Error("ReadString", "useless");
95  return nullptr;
96  }
97  void WriteString(const char * /*s*/) final { Error("WriteString", "useless"); }
98 
99  Version_t ReadVersionForMemberWise(const TClass * /*cl*/ = nullptr) final
100  {
101  Error("ReadVersionForMemberWise", "not defined in text-based streamers");
102  return 0;
103  }
104  UInt_t WriteVersionMemberWise(const TClass * /*cl*/, Bool_t /*useBcnt*/ = kFALSE) final
105  {
106  Error("WriteVersionMemberWise", "not defined in text-based streamers");
107  return 0;
108  }
109 
110  TObject *ReadObject(const TClass * /*cl*/) final
111  {
112  Error("ReadObject", "not yet implemented for text-based streamers");
113  return nullptr;
114  }
115 
116  // Utilities for TClass
117  Int_t ReadClassEmulated(const TClass * /*cl*/, void * /*object*/, const TClass * /*onfile_class*/ = nullptr) final
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  ClassDefOverride(TBufferText, 0); // a TBuffer subclass for all text-based streamers
141 };
142 
143 #endif
void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Float16_t to buffer.
Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
Read array of Double32_t from buffer.
void SetByteCount(UInt_t, Bool_t=kFALSE) final
Definition: TBufferText.h:81
static const char * ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Double32_t to buffer.
void ReadFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
read a Float16_t from the buffer
TObject * ReadObject(const TClass *) final
Definition: TBufferText.h:110
Int_t CheckByteCount(UInt_t, UInt_t, const char *) final
Definition: TBufferText.h:80
Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=nullptr) override
Read array of Double32_t from buffer.
short Version_t
Definition: RtypesCore.h:61
float Float_t
Definition: RtypesCore.h:53
void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
read array of Double32_t from buffer
void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=nullptr) override
stream object to/from buffer
char * ReadString(char *, Int_t) final
Definition: TBufferText.h:92
void WriteFastArrayFloat16(const Float_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Float16_t to buffer.
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
void ReadDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
read a Double32_t from the buffer
Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection) final
Read one collection of objects from the buffer using the StreamerInfoLoopAction.
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
Read array of Float16_t from buffer.
virtual ~TBufferText()
destructor
Definition: TBufferText.cxx:61
Int_t ReadBuf(void *, Int_t) final
Definition: TBufferText.h:85
ClassDefOverride(TBufferText, 0)
void WriteBuf(const void *, Int_t) final
Definition: TBufferText.h:90
Int_t WriteClassBuffer(const TClass *cl, void *pointer) override
Function called by the Streamer functions to serialize object at p to buffer b.
Int_t ReadClassEmulated(const TClass *, void *, const TClass *=nullptr) final
Definition: TBufferText.h:117
Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object) final
Read one collection of objects from the buffer using the StreamerInfoLoopAction.
Definition: TBufferText.cxx:69
void WriteString(const char *) final
Definition: TBufferText.h:97
Int_t ReadClassBuffer(const TClass *, void *, const TClass *=nullptr) override
Deserialize information from a buffer into an object.
static const char * fgFloatFmt
! printf argument for floats, either "%f" or "%e" or "%10f" and so on
Definition: TBufferText.h:137
void WriteDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
write a Double32_t to the buffer
void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits) final
read array of Float16_t from buffer
TBufferText()
Default constructor.
Definition: TBufferText.cxx:43
Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele=nullptr) override
Read array of Float16_t from buffer.
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
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
Version_t ReadVersionForMemberWise(const TClass *=nullptr) final
Definition: TBufferText.h:99
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 met...
Definition: TBufferText.h:21
double Double_t
Definition: RtypesCore.h:55
void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue) final
read array of Float16_t from buffer
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e" to change format only for doubles...
void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue) final
Read a Double32_t from the buffer when the factor and minimun value have been specified see comments ...
static const char * GetDoubleFormat()
return current printf format for double members, default "%.14e"
Mother of all ROOT objects.
Definition: TObject.h:37
void WriteFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
write a Float16_t to the buffer
virtual void WriteBaseClass(void *start, TStreamerBase *elem)
Write data of base class.
void ReadWithNbits(Float_t *ptr, Int_t nbits) final
Read a Float16_t from the buffer when the number of bits is specified (explicitly or not) see comment...
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
static const char * GetFloatFormat()
return current printf format for float members, default "%e"
UInt_t WriteVersionMemberWise(const TClass *, Bool_t=kFALSE) final
Definition: TBufferText.h:104
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.
Version_t ReadVersionNoCheckSum(UInt_t *, UInt_t *) final
Definition: TBufferText.h:83
void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Double32_t to buffer.
Int_t CheckByteCount(UInt_t, UInt_t, const TClass *) final
Definition: TBufferText.h:79
void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=nullptr) final
read array of Float16_t from buffer
const Int_t n
Definition: legend1.C:16
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33
void SkipVersion(const TClass *cl=nullptr) final
Skip class version from I/O buffer.