Logo ROOT  
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 
17 class TStreamerBase;
18 class TExMap;
19 
20 class TBufferText : public TBufferIO {
21 
22 protected:
23  TBufferText();
24  TBufferText(TBuffer::EMode mode, TObject *parent = nullptr);
25 
26 public:
27  virtual ~TBufferText();
28 
29  // virtual TBuffer methods, which are generic for all text-based streamers
30 
31  void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass = nullptr) override;
32  void StreamObject(void *obj, const char *className, const TClass *onFileClass = nullptr) override;
33  void StreamObject(TObject *obj) override;
35 
36  Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object) final;
37  Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection,
38  void *end_collection) final;
39  Int_t
40  ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection) final;
41 
42  void ReadFloat16(Float_t *f, TStreamerElement *ele = nullptr) final;
43  void WriteFloat16(Float_t *f, TStreamerElement *ele = nullptr) final;
44  void ReadDouble32(Double_t *d, TStreamerElement *ele = nullptr) final;
45  void WriteDouble32(Double_t *d, TStreamerElement *ele = nullptr) final;
46  void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue) final;
47  void ReadWithNbits(Float_t *ptr, Int_t nbits) final;
48  void ReadWithFactor(Double_t *ptr, Double_t factor, Double_t minvalue) final;
49  void ReadWithNbits(Double_t *ptr, Int_t nbits) final;
50 
51  Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele = nullptr) override;
52  Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele = nullptr) override;
53 
54  Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele = nullptr) final;
56 
57  void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele = nullptr) final;
58  void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele = nullptr) final;
59  void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue) final;
60  void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits) final;
61  void ReadFastArrayWithFactor(Double_t *ptr, Int_t n, Double_t factor, Double_t minvalue) final;
62  void ReadFastArrayWithNbits(Double_t *ptr, Int_t n, Int_t nbits) final;
63 
64  void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele = nullptr) final;
65  void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele = nullptr) final;
66 
67  void WriteFastArrayFloat16(const Float_t *d, Int_t n, TStreamerElement *ele = nullptr) final;
68  void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele = nullptr) final;
69 
70  // Utilities for TClass
71  Int_t ReadClassBuffer(const TClass * /*cl*/, void * /*pointer*/, const TClass * /*onfile_class*/ = nullptr) override;
72  Int_t ReadClassBuffer(const TClass * /*cl*/, void * /*pointer*/, Int_t /*version*/, UInt_t /*start*/,
73  UInt_t /*count*/, const TClass * /*onfile_class*/ = nullptr) override;
74  Int_t WriteClassBuffer(const TClass *cl, void *pointer) override;
75 
76  // virtual abstract TBuffer methods, which are not used in text streaming
77 
78  Int_t CheckByteCount(UInt_t /* startpos */, UInt_t /* bcnt */, const TClass * /* clss */) final { return 0; }
79  Int_t CheckByteCount(UInt_t /* startpos */, UInt_t /* bcnt */, const char * /* classname */) final { return 0; }
80  void SetByteCount(UInt_t /* cntpos */, Bool_t /* packInVersion */ = kFALSE) final {}
81  void SkipVersion(const TClass *cl = nullptr) final;
82  Version_t ReadVersionNoCheckSum(UInt_t *, UInt_t *) final { return 0; }
83 
84  Int_t ReadBuf(void * /*buf*/, Int_t /*max*/) final
85  {
86  Error("ReadBuf", "useless in text streamers");
87  return 0;
88  }
89  void WriteBuf(const void * /*buf*/, Int_t /*max*/) final { Error("WriteBuf", "useless in text streamers"); }
90 
91  char *ReadString(char * /*s*/, Int_t /*max*/) final
92  {
93  Error("ReadString", "useless");
94  return nullptr;
95  }
96  void WriteString(const char * /*s*/) final { Error("WriteString", "useless"); }
97 
98  Version_t ReadVersionForMemberWise(const TClass * /*cl*/ = nullptr) final
99  {
100  Error("ReadVersionForMemberWise", "not defined in text-based streamers");
101  return 0;
102  }
103  UInt_t WriteVersionMemberWise(const TClass * /*cl*/, Bool_t /*useBcnt*/ = kFALSE) final
104  {
105  Error("WriteVersionMemberWise", "not defined in text-based streamers");
106  return 0;
107  }
108 
109  TObject *ReadObject(const TClass * /*cl*/) final
110  {
111  Error("ReadObject", "not yet implemented for text-based streamers");
112  return nullptr;
113  }
114 
115  // Utilities for TClass
116  Int_t ReadClassEmulated(const TClass * /*cl*/, void * /*object*/, const TClass * /*onfile_class*/ = nullptr) final
117  {
118  Error("ReadClassEmulated", "not defined in text-based streamers");
119  return 0;
120  }
121 
122  virtual void WriteBaseClass(void *start, TStreamerBase *elem);
123 
124  virtual void ReadBaseClass(void *start, TStreamerBase *elem);
125 
126  static void SetFloatFormat(const char *fmt = "%e");
127  static const char *GetFloatFormat();
128  static void SetDoubleFormat(const char *fmt = "%.14e");
129  static const char *GetDoubleFormat();
130 
131  static void CompactFloatString(char *buf, unsigned len);
132  static const char *ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize = kFALSE);
133  static const char *ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize = kFALSE);
134 
135 protected:
136  static const char *fgFloatFmt; ///<! printf argument for floats, either "%f" or "%e" or "%10f" and so on
137  static const char *fgDoubleFmt; ///<! printf argument for doubles, either "%f" or "%e" or "%10f" and so on
138 
139  ClassDefOverride(TBufferText, 0); // a TBuffer subclass for all text-based streamers
140 };
141 
142 #endif
TBufferText::ReadObject
TObject * ReadObject(const TClass *) final
Definition: TBufferText.h:109
TBufferText::GetFloatFormat
static const char * GetFloatFormat()
return current printf format for float members, default "%e"
Definition: TBufferText.cxx:806
TBufferText::CheckByteCount
Int_t CheckByteCount(UInt_t, UInt_t, const char *) final
Definition: TBufferText.h:79
TBufferText::SkipVersion
void SkipVersion(const TClass *cl=nullptr) final
Skip class version from I/O buffer.
Definition: TBufferText.cxx:675
n
const Int_t n
Definition: legend1.C:16
TBufferText::ReadVersionNoCheckSum
Version_t ReadVersionNoCheckSum(UInt_t *, UInt_t *) final
Definition: TBufferText.h:82
TBufferText::SetByteCount
void SetByteCount(UInt_t, Bool_t=kFALSE) final
Definition: TBufferText.h:80
Version_t
short Version_t
Definition: RtypesCore.h:65
TBufferText::ReadFastArrayDouble32
void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
read array of Double32_t from buffer
Definition: TBufferText.cxx:620
f
#define f(i)
Definition: RSha256.hxx:104
TBufferText::ReadStaticArrayFloat16
Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
Read array of Float16_t from buffer.
Definition: TBufferText.cxx:580
TBufferText::ReadBuf
Int_t ReadBuf(void *, Int_t) final
Definition: TBufferText.h:84
TBufferText::SetDoubleFormat
static void SetDoubleFormat(const char *fmt="%.14e")
set printf format for double members, default "%.14e" use it after SetFloatFormat,...
Definition: TBufferText.cxx:815
TBufferText::WriteArrayFloat16
void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Float16_t to buffer.
Definition: TBufferText.cxx:643
TBufferText::ApplySequenceVecPtr
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.
Definition: TBufferText.cxx:102
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TBufferText::WriteFastArrayDouble32
void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Double32_t to buffer.
Definition: TBufferText.cxx:667
TBufferText::ReadFloat16
void ReadFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
read a Float16_t from the buffer
Definition: TBufferText.cxx:488
Float_t
float Float_t
Definition: RtypesCore.h:57
TBufferText::ClassDefOverride
ClassDefOverride(TBufferText, 0)
TBufferText::ReadArrayDouble32
Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=nullptr) override
Read array of Double32_t from buffer.
Definition: TBufferText.cxx:572
TBufferText::WriteBuf
void WriteBuf(const void *, Int_t) final
Definition: TBufferText.h:89
TBufferText::WriteString
void WriteString(const char *) final
Definition: TBufferText.h:96
TBufferText::ReadDouble32
void ReadDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
read a Double32_t from the buffer
Definition: TBufferText.cxx:496
TBufferText::~TBufferText
virtual ~TBufferText()
destructor
Definition: TBufferText.cxx:61
TBufferText::WriteFastArrayFloat16
void WriteFastArrayFloat16(const Float_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Float16_t to buffer.
Definition: TBufferText.cxx:659
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
v
@ v
Definition: rootcling_impl.cxx:3635
TBuffer::StreamObject
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=0)=0
bool
TBufferText::ReadClassBuffer
Int_t ReadClassBuffer(const TClass *, void *, const TClass *=nullptr) override
Deserialize information from a buffer into an object.
Definition: TBufferText.cxx:323
TBufferText
Base class for text-based streamers like TBufferJSON or TBufferXML Special actions list will use meth...
Definition: TBufferText.h:20
TBufferText::ReadFastArrayWithNbits
void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits) final
read array of Float16_t from buffer
Definition: TBufferText.cxx:612
TBufferText::ApplySequence
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
TBufferText::WriteClassBuffer
Int_t WriteClassBuffer(const TClass *cl, void *pointer) override
Function called by the Streamer functions to serialize object at p to buffer b.
Definition: TBufferText.cxx:179
TBufferText::ReadClassEmulated
Int_t ReadClassEmulated(const TClass *, void *, const TClass *=nullptr) final
Definition: TBufferText.h:116
TBufferIO.h
TBuffer::EMode
EMode
Definition: TBuffer.h:73
TBufferText::ReadArrayFloat16
Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele=nullptr) override
Read array of Float16_t from buffer.
Definition: TBufferText.cxx:564
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TBufferText::ReadFastArrayWithFactor
void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue) final
read array of Float16_t from buffer
Definition: TBufferText.cxx:604
TBufferText::TBufferText
TBufferText()
Default constructor.
Definition: TBufferText.cxx:43
TBufferText::fgFloatFmt
static const char * fgFloatFmt
! printf argument for floats, either "%f" or "%e" or "%10f" and so on
Definition: TBufferText.h:136
TBufferText::StreamObject
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=0)=0
TBufferText::ReadWithNbits
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...
Definition: TBufferText.cxx:518
unsigned int
TBufferText::WriteDouble32
void WriteDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
write a Double32_t to the buffer
Definition: TBufferText.cxx:556
TBufferIO
Direct subclass of TBuffer, implements common methods for TBufferFile and TBufferText classes.
Definition: TBufferIO.h:30
TBufferText::CompactFloatString
static void CompactFloatString(char *buf, unsigned len)
method compress float string, excluding exp and/or move float point
Definition: TBufferText.cxx:704
Double_t
double Double_t
Definition: RtypesCore.h:59
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TBufferText::SetFloatFormat
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e" to change format only for doubles,...
Definition: TBufferText.cxx:795
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TBufferText::ReadVersionForMemberWise
Version_t ReadVersionForMemberWise(const TClass *=nullptr) final
Definition: TBufferText.h:98
TBufferText::ConvertDouble
static const char * ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
Definition: TBufferText.cxx:849
TBufferText::WriteVersionMemberWise
UInt_t WriteVersionMemberWise(const TClass *, Bool_t=kFALSE) final
Definition: TBufferText.h:103
TBufferText::ReadBaseClass
virtual void ReadBaseClass(void *start, TStreamerBase *elem)
Read data of base class.
Definition: TBufferText.cxx:691
d
#define d(i)
Definition: RSha256.hxx:102
TExMap
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33
TBufferText::WriteBaseClass
virtual void WriteBaseClass(void *start, TStreamerBase *elem)
Write data of base class.
Definition: TBufferText.cxx:683
TBufferText::WriteFloat16
void WriteFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
write a Float16_t to the buffer
Definition: TBufferText.cxx:548
TBufferText::fgDoubleFmt
static const char * fgDoubleFmt
! printf argument for doubles, either "%f" or "%e" or "%10f" and so on
Definition: TBufferText.h:137
TBufferText::CheckByteCount
Int_t CheckByteCount(UInt_t, UInt_t, const TClass *) final
Definition: TBufferText.h:78
TStreamerInfoActions::TActionSequence
Definition: TStreamerInfoActions.h:172
TBufferText::ReadWithFactor
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 ...
Definition: TBufferText.cxx:507
TBufferText::GetDoubleFormat
static const char * GetDoubleFormat()
return current printf format for double members, default "%.14e"
Definition: TBufferText.cxx:825
TStreamerElement
Definition: TStreamerElement.h:33
TStreamerBase
Definition: TStreamerElement.h:151
TBufferText::ReadStaticArrayDouble32
Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
Read array of Double32_t from buffer.
Definition: TBufferText.cxx:588
TBufferText::WriteArrayDouble32
void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Double32_t to buffer.
Definition: TBufferText.cxx:651
TBufferText::ReadString
char * ReadString(char *, Int_t) final
Definition: TBufferText.h:91
TBufferText::ReadFastArrayFloat16
void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=nullptr) final
read array of Float16_t from buffer
Definition: TBufferText.cxx:596
int
TBufferText::ConvertFloat
static const char * ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
Definition: TBufferText.cxx:833