Go to the documentation of this file.
4 #ifndef tools_rroot_rbuf
5 #define tools_rroot_rbuf
9 #include "../charp_out"
33 static void read_swap_2(
char* a_pos,
char* a_x) {
37 static void read_swap_4(
char* a_pos,
char* a_x) {
44 static void read_swap_8(
char* a_pos,
char* a_x) {
58 static void read_nswp_2(
char* a_pos,
char* a_x) {
59 ::memcpy(a_x,a_pos,2);
61 static void read_nswp_4(
char* a_pos,
char* a_x) {
62 ::memcpy(a_x,a_pos,4);
64 static void read_nswp_8(
char* a_pos,
char* a_x) {
65 ::memcpy(a_x,a_pos,8);
72 static const std::string& s_class() {
73 static const std::string s_v(
"tools::rroot::rbuf");
76 typedef void (*r_2_func)(
char*,
char*);
77 typedef void (*r_4_func)(
char*,
char*);
78 typedef void (*r_8_func)(
char*,
char*);
80 rbuf(std::ostream& a_out,
bool a_byte_swap,
const char* a_eob,
char*& a_pos)
91 mem::increment(s_class().c_str());
97 mem::decrement(s_class().c_str());
111 mem::increment(s_class().c_str());
146 bool read(
unsigned char& a_x) {
147 if(!_check_eob<unsigned char>(a_x))
return false;
151 bool read(
unsigned short& a_x) {
152 if(!_check_eob<unsigned short>(a_x))
return false;
154 m_pos +=
sizeof(
unsigned short);
159 if(!_check_eob<unsigned int>(a_x))
return false;
161 m_pos +=
sizeof(
unsigned int);
166 if(!_check_eob<uint64>(a_x))
return false;
173 if(!_check_eob<float>(a_x))
return false;
175 m_pos +=
sizeof(float);
180 if(!_check_eob<double>(a_x))
return false;
182 m_pos +=
sizeof(double);
187 if(!_check_eob<char>(a_x))
return false;
192 if(!_check_eob<short>(a_x))
return false;
194 m_pos +=
sizeof(short);
199 if(!_check_eob<int>(a_x))
return false;
201 m_pos +=
sizeof(int);
206 if(!_check_eob<int64>(a_x))
return false;
214 if(!
read(nwh)) {a_x.clear();
return false;}
217 if(!
read(nchars)) {a_x.clear();
return false;}
222 m_out << s_class() <<
"::read(string) :"
223 <<
" negative char number " << nchars <<
"." << std::endl;
228 m_out << s_class() <<
"::read(string) :"
229 <<
" try to access out of buffer " <<
long_out(nchars) <<
" bytes "
236 ::memcpy((
char*)a_x.c_str(),
m_pos,nchars);
242 unsigned char uc = 0;
243 bool status =
read(uc);
247 bool read(std::vector<std::string>& a_a) {
249 if(!
read(n)) {a_a.clear();
return false;}
250 for(
int index=0;index<n;index++) {
252 if(!
read(s)) {a_a.clear();
return false;}
263 uint32 l = n *
sizeof(
unsigned char);
265 for(
uint32 i = 0; i < n; i++) {
267 if(!
read(uc))
return false;
268 b[i] = uc?
true:
false;
274 uint32 l = n *
sizeof(char);
282 uint32 l = n *
sizeof(
unsigned char);
284 ::memcpy(c,
m_pos, l);
291 if(!a_n)
return true;
293 uint32 l = a_n *
sizeof(T);
295 m_out << s_class() <<
"::read_fast_array :"
296 <<
" try to access out of buffer " <<
long_out(l) <<
" bytes "
303 for(
uint32 i=0;i<a_n;i++) {
304 if(!
read(*(a_a+i)))
return false;
307 ::memcpy(a_a,
m_pos,l);
317 if(!
read(n)) {a_n = 0;
return false;}
320 if(!a_n)
return true;
322 uint32 l = a_n *
sizeof(T);
329 if(!a_a) {a_n=0;
return false;}
332 if(a_n>a_sz)
return false;
336 for(
uint32 i=0;i<a_n;i++) {
337 if(!
read(*(a_a+i))) {
338 if(owner) {
delete [] a_a;a_a = 0;}
344 ::memcpy(a_a,
m_pos,l);
355 if(!
buffer) {a_v.clear();
return true;}
357 for(
uint32 index=0;index<n;index++) {
358 a_v[index] =
buffer[index];
367 if(!
read(n)) {a_v.clear();
return false;}
369 for(
int index=0;index<n;index++) {
377 m_out <<
"tools::rroot::rbuf::check_eob :"
378 <<
" try to access out of buffer " << n <<
" bytes."
390 m_out << s_class() <<
" : " <<
stype(T()) <<
" : "
391 <<
" try to access out of buffer " <<
long_out(
sizeof(T)) <<
" bytes"