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#include "TString.h"
17
18class TStreamerBase;
19class TExMap;
20
21class TBufferText : public TBufferIO {
22
23protected:
25 TBufferText(TBuffer::EMode mode, TObject *parent = nullptr);
26
27public:
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
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
136protected:
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
#define d(i)
Definition: RSha256.hxx:102
#define f(i)
Definition: RSha256.hxx:104
short Version_t
Definition: RtypesCore.h:63
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
float Float_t
Definition: RtypesCore.h:55
Direct subclass of TBuffer, implements common methods for TBufferFile and TBufferText classes.
Definition: TBufferIO.h:30
Base class for text-based streamers like TBufferJSON or TBufferXML Special actions list will use meth...
Definition: TBufferText.h:21
Int_t CheckByteCount(UInt_t, UInt_t, const TClass *) final
Definition: TBufferText.h:79
static const char * ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
TObject * ReadObject(const TClass *) final
Definition: TBufferText.h:110
char * ReadString(char *, Int_t) final
Definition: TBufferText.h:92
static const char * GetFloatFormat()
return current printf format for float members, default "%e"
Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=nullptr) override
Read array of Double32_t from buffer.
void WriteBuf(const void *, Int_t) final
Definition: TBufferText.h:90
void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=nullptr) final
read array of Float16_t from buffer
virtual ~TBufferText()
destructor
Definition: TBufferText.cxx:61
ClassDefOverride(TBufferText, 0)
void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
read array of Double32_t from buffer
Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele=nullptr) override
Read array of Float16_t from buffer.
Version_t ReadVersionForMemberWise(const TClass *=nullptr) final
Definition: TBufferText.h:99
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...
TBufferText()
Default constructor.
Definition: TBufferText.cxx:43
void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Double32_t to buffer.
Int_t WriteClassBuffer(const TClass *cl, void *pointer) override
Function called by the Streamer functions to serialize object at p to buffer b.
static void CompactFloatString(char *buf, unsigned len)
method compress float string, excluding exp and/or move float point
void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue) final
read array of Float16_t from buffer
static const char * ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=nullptr) override
stream object to/from buffer
Int_t ReadBuf(void *, Int_t) final
Definition: TBufferText.h:85
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.
void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Float16_t to buffer.
void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits) final
read array of Float16_t from buffer
Int_t CheckByteCount(UInt_t, UInt_t, const char *) final
Definition: TBufferText.h:80
void ReadFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
read a Float16_t from the buffer
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 SkipVersion(const TClass *cl=nullptr) final
Skip class version from I/O buffer.
Int_t ReadClassEmulated(const TClass *, void *, const TClass *=nullptr) final
Definition: TBufferText.h:117
virtual void WriteBaseClass(void *start, TStreamerBase *elem)
Write data of base class.
void SetByteCount(UInt_t, Bool_t=kFALSE) final
Definition: TBufferText.h:81
void WriteString(const char *) final
Definition: TBufferText.h:97
Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
Read array of Float16_t from buffer.
Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
Read array of Double32_t from buffer.
static const char * fgDoubleFmt
! printf argument for doubles, either "%f" or "%e" or "%10f" and so on
Definition: TBufferText.h:138
virtual void ReadBaseClass(void *start, TStreamerBase *elem)
Read data of base class.
UInt_t WriteVersionMemberWise(const TClass *, Bool_t=kFALSE) final
Definition: TBufferText.h:104
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e" to change format only for doubles,...
Int_t ReadClassBuffer(const TClass *, void *, const TClass *=nullptr) override
Deserialize information from a buffer into an object.
void WriteFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
write a Float16_t to the buffer
Version_t ReadVersionNoCheckSum(UInt_t *, UInt_t *) final
Definition: TBufferText.h:83
static const char * GetDoubleFormat()
return current printf format for double members, default "%.14e"
void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Double32_t to buffer.
void ReadDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
read a Double32_t from the buffer
void WriteFastArrayFloat16(const Float_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Float16_t to buffer.
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 ...
void WriteDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
write a Double32_t to the buffer
static const char * fgFloatFmt
! printf argument for floats, either "%f" or "%e" or "%10f" and so on
Definition: TBufferText.h:137
static void SetDoubleFormat(const char *fmt="%.14e")
set printf format for double members, default "%.14e" use it after SetFloatFormat,...
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=0)=0
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
const Int_t n
Definition: legend1.C:16