GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BufferIO.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef ADF_BufferIO
24 #define ADF_BufferIO
25 #define ADF_BUFFERIO_H ADF_BufferIO
26 
27 #ifndef ADF_BaseBuffer
28 #include "BaseBuffer.h"
29 #endif
30 
31 #include <stdio.h>
32 #include <iostream>
33 #include <string>
34 
35 namespace ADF {
36 
38 
48 class CompositeFrame;
49 
50 class BufferIO : protected BaseBuffer
51 {
52 public:
53  friend class CompositeFrame;
54 
55 protected:
57  mutable EStatus fStatus;
60 
61 private:
63  Char_t * fInner;
65  Char_t * fOuter;
67  UInt_t fRealInnerSize;
69  UInt_t fRealOuterSize;
70 
71 protected:
73  Char_t * fBufferIO;
75  UInt_t fSize;
77  UInt_t fRealSize;
78 
80  mutable UInt_t fCurrent;
81 
82 protected:
83  void AllocInner(UInt_t);
85  { fEndian = e; }
86 
88  void SetCurrent(const char = 'i');
89 
90 public:
92 
94  explicit BufferIO(UInt_t s = aByte);
95  virtual ~BufferIO();
96 
98  Char_t *Address()
99  { return fBufferIO; }
101  Char_t *CurrentAddress()
102  { return fBufferIO + Offset(); }
103 
104  Bool_t IsStatus(BufferIO::EStatus s) const
105  { return fStatus == s; }
107  { fStatus = s;}
108 
110  { return fStatus; }
111 
113  { return fEndian; }
114  Bool_t IsEndian(BaseBuffer::EEndian e) const
115  { return fEndian == e ; }
116 
118 
131  virtual Bool_t Link(const Char_t *from, UInt_t from_size);
132 
134 
144  virtual Bool_t Copy(const Char_t *from, UInt_t from_size);
145 
147 
149  virtual Bool_t Link(const BufferIO &buf, UInt_t pos, UInt_t size);
150 
152 
157  virtual Char_t *Unlink();
158 
160  virtual Bool_t IsLinked()
161  { return fBufferIO != fInner; }
162 
164 
172  static Bool_t Copy(const BufferIO &from, BufferIO &to, UInt_t size, UInt_t off_from = 0u)
173  {
174  if ( off_from + size > from.Size() )
175  return false;
176  if ( size > to.FreeSize() )
177  return false ;
178  BaseBuffer::Copy(from.GetAddress()+off_from,to.CurrentAddress(),size);
179  to.SetOffset(to.Offset()+size);
180  return true;
181  }
182 
184 
189  /* static Bool_t Copy(const BufferIO &from, BufferIO &to, UInt_t size)
190  { if ( size > to.FreeSize() )
191  return false ;
192  BaseBuffer::Copy(from.GetAddress(),to.GetCurrentAddress(),size);
193  to.SetOffset(to.Offset()+size);
194  return true;
195  }
196  */
197 
199 
204  static Bool_t Copy(const BufferIO &from, BufferIO &to)
205  { return Copy(from,to,from.Size()); }
206 
208 
211  static BufferIO *New(BaseBuffer::EEndian e, UInt_t s = aByte);
212 
214 
216  const Char_t *GetAddress() const
217  { return fBufferIO; }
218 
220  UInt_t Size() const
221  { return fSize; }
222 
224 
233  UInt_t SetEffectiveSize(UInt_t size = kMaxUInt_t);
234 
236  UInt_t FreeSize() const
237  { return fSize - fCurrent; }
238 
240  UInt_t Offset() const
241  { return fCurrent ; }
242 
244 
250  UInt_t SetOffset(UInt_t off = 0u) const;
251 
253 
256  UInt_t SetOffset(const Char_t *off) const;
257 
259 
262  Bool_t IsAnOffset(const Char_t *off, UInt_t &pos) const;
263 
265 
267  virtual void Reset();
268  virtual void FastReset();
269 
271 
284  virtual Bool_t Expand(UInt_t new_size);
285 
287  virtual Bool_t Reserve(UInt_t size);
288 
289  virtual BufferIO &operator << (Char_t);
290  virtual BufferIO &operator << (UChar_t);
291  virtual BufferIO &operator << (Short_t);
292  virtual BufferIO &operator << (UShort_t);
293  virtual BufferIO &operator << (Int_t);
294  virtual BufferIO &operator << (UInt_t);
295  virtual BufferIO &operator << (Float_t);
296  virtual BufferIO &operator << (Double_t);
297  virtual BufferIO &operator << (Long_t);
298  virtual BufferIO &operator << (ULong_t);
299  virtual BufferIO &operator << (Long64_t);
300  virtual BufferIO &operator << (ULong64_t);
301 
303  virtual BufferIO &operator << (std::string);
304 
305  virtual const BufferIO &operator>> (Char_t &) const;
306  virtual const BufferIO &operator>> (UChar_t &) const;
307  virtual const BufferIO &operator>> (Short_t &) const;
308  virtual const BufferIO &operator>> (UShort_t &) const;
309  virtual const BufferIO &operator>> (Int_t &) const;
310  virtual const BufferIO &operator>> (UInt_t &) const;
311  virtual const BufferIO &operator>> (Float_t &) const;
312  virtual const BufferIO &operator>> (Double_t &) const;
313  virtual const BufferIO &operator>> (Long_t &) const;
314  virtual const BufferIO &operator>> (ULong_t &) const;
315  virtual const BufferIO &operator>> (Long64_t &) const;
316  virtual const BufferIO &operator>> (ULong64_t &) const;
317 
319  virtual const BufferIO &operator>> (std::string &) const;
320 
321 
323  virtual UInt_t FillWith(Char_t c, UInt_t how_many);
324 
326 
330  virtual UInt_t Export(Char_t *, UInt_t) const;
331  virtual UInt_t Export(UShort_t *, UInt_t) const;
332  virtual UInt_t Export(Short_t *, UInt_t) const;
333  virtual UInt_t Export(UInt_t *, UInt_t) const;
334  virtual UInt_t Export(Int_t *, UInt_t) const;
335  virtual UInt_t Export(Float_t *, UInt_t) const;
336 
338 
341  virtual UInt_t Export(Double_t *, UInt_t) const;
342 
343 
345 
348  UInt_t Import(const Char_t *from, UInt_t size_ext_buf);
349 
351 
354  virtual UInt_t Import(const UShort_t *, UInt_t);
355  virtual UInt_t Import(const Short_t *, UInt_t);
356  virtual UInt_t Import(const UInt_t *, UInt_t);
357  virtual UInt_t Import(const Int_t *, UInt_t);
358  virtual UInt_t Import(const Float_t *, UInt_t);
360 
363  virtual UInt_t Import(const Double_t *, UInt_t);
364 
366 
369  virtual UInt_t Import(const BufferIO &, UInt_t);
370 
372 
378  virtual UInt_t Import(FILE *, UInt_t);
379 
381 
385  virtual UInt_t Export(FILE *, UInt_t) const;
386 
388  virtual UInt_t Import(std::istream &, UInt_t);
389 
391  virtual UInt_t Export(std::ostream &, UInt_t) const ;
392 };
393 // inline BufferIO members
394 inline BufferIO &BufferIO::operator << (Char_t data)
395 {
396  if (FreeSize()>=sizeof(Char_t)) {
397  ::memcpy((fBufferIO+fCurrent),&data,sizeof(Char_t));
398  fCurrent += sizeof(Char_t);
399  }
400  else fStatus = BaseBuffer::kFail ;
401  return (*this);
402 }
403 inline BufferIO &BufferIO::operator << (UChar_t data)
404 {
405  if (FreeSize()>=sizeof(Char_t)) {
406  ::memcpy((fBufferIO+fCurrent),&data,sizeof(UChar_t));
407  fCurrent += sizeof(Char_t);
408  }
409  else fStatus = BaseBuffer::kFail ;
410  return (*this);
411 }
412 inline BufferIO &BufferIO::operator << (Short_t data)
413 {
414  if (FreeSize()>=sizeof(Short_t)) {
415  ::memcpy((fBufferIO+fCurrent),&data,sizeof(Short_t));
416  fCurrent += sizeof(Short_t);
417  }
418  else fStatus = BaseBuffer::kFail ;
419  return (*this);
420 }
421 inline BufferIO &BufferIO::operator << (UShort_t data)
422 {
423  if (FreeSize()>=sizeof(Short_t)) {
424  ::memcpy((fBufferIO+fCurrent),&data,sizeof(UShort_t));
425  fCurrent += sizeof(UShort_t);
426  }
427  else fStatus = BaseBuffer::kFail ;
428  return (*this);
429 }
430 inline BufferIO &BufferIO::operator << (Int_t data)
431 {
432  if (FreeSize()>=sizeof(Int_t)) {
433  ::memcpy((fBufferIO+fCurrent),&data,sizeof(Int_t));
434  fCurrent += sizeof(Int_t);
435  }
436  else fStatus = BaseBuffer::kFail ;
437  return (*this);
438 }
439 inline BufferIO &BufferIO::operator << (UInt_t data)
440 {
441  if (FreeSize()>=sizeof(Int_t)) {
442  ::memcpy((fBufferIO+fCurrent),&data,sizeof(UInt_t));
443  fCurrent += sizeof(UInt_t);
444  }
445  else fStatus = BaseBuffer::kFail ;
446  return (*this);
447 }
448 inline BufferIO &BufferIO::operator << (Float_t data)
449 {
450  if (FreeSize()>=sizeof(Float_t)) {
451  ::memcpy((fBufferIO+fCurrent),&data,sizeof(Float_t));
452  fCurrent += sizeof(Float_t);
453  }
454  else fStatus = BaseBuffer::kFail ;
455  return (*this);
456 }
457 inline BufferIO &BufferIO::operator << (Double_t data)
458 {
459  if (FreeSize()>=sizeof(Double_t)) {
460  ::memcpy((fBufferIO+fCurrent),&data,sizeof(Double_t));
461  fCurrent += sizeof(Double_t);
462  }
463  else fStatus = BaseBuffer::kFail ;
464  return (*this);
465 }
466 
467 inline BufferIO &BufferIO::operator << (Long_t data)
468 {
469  // long are written on 64 bits whatever the system
470  if (FreeSize()>=sizeof(Long64_t)) {
471  if ( sizeof(Long_t) == 8 ) {
472  ::memcpy((fBufferIO+fCurrent),&data,sizeof(Long_t));
473  }
474  else {
475  if (data < 0) {
476  fBufferIO[fCurrent+0] = (char) -1;
477  fBufferIO[fCurrent+1] = (char) -1;
478  fBufferIO[fCurrent+2] = (char) -1;
479  fBufferIO[fCurrent+3] = (char) -1;
480  } else {
481  fBufferIO[fCurrent+0] = 0;
482  fBufferIO[fCurrent+1] = 0;
483  fBufferIO[fCurrent+2] = 0;
484  fBufferIO[fCurrent+3] = 0;
485  }
486  ::memcpy((fBufferIO+fCurrent+4), &data, 4);
487  }
488  fCurrent += sizeof(Long64_t);
489  }
490  else fStatus = BaseBuffer::kFail ;
491  return (*this);
492 }
493 
494 inline BufferIO &BufferIO::operator << (ULong_t data)
495 {
496  if (FreeSize()>=sizeof(ULong64_t)){
497  if ( sizeof(ULong_t) == 8 ) {
498  ::memcpy((fBufferIO+fCurrent),&data,sizeof(ULong_t));
499  }
500  else {
501 // if (data < 0) {
502 // fBufferIO[fCurrent+0] = (char) -1;
503 // fBufferIO[fCurrent+1] = (char) -1;
504 // fBufferIO[fCurrent+2] = (char) -1;
505 // fBufferIO[fCurrent+3] = (char) -1;
506 // } else {
507  fBufferIO[fCurrent+0] = 0;
508  fBufferIO[fCurrent+1] = 0;
509  fBufferIO[fCurrent+2] = 0;
510  fBufferIO[fCurrent+3] = 0;
511 // }
512  ::memcpy((fBufferIO+fCurrent+4), &data, 4);
513  }
514  fCurrent += sizeof(ULong64_t);
515  }
516  else fStatus = BaseBuffer::kFail ;
517  return (*this);
518 }
519 
520 inline BufferIO &BufferIO::operator << (Long64_t data)
521 {
522  if (FreeSize()>=sizeof(Long64_t)) {
523  ::memcpy((fBufferIO+fCurrent),&data,sizeof(Long64_t));
524  fCurrent += sizeof(Long64_t);
525  }
526  else fStatus = BaseBuffer::kFail ;
527  return (*this);
528 }
529 inline BufferIO &BufferIO::operator << (ULong64_t data)
530 {
531  if (FreeSize()>=sizeof(ULong64_t)) {
532  ::memcpy((fBufferIO+fCurrent),&data,sizeof(ULong64_t));
533  fCurrent += sizeof(ULong64_t);
534  }
535  else fStatus = BaseBuffer::kFail ;
536  return (*this);
537 }
538 inline BufferIO &BufferIO::operator << (std::string data)
539 {
540  UShort_t size_string = (UShort_t)data.size();
541  UShort_t size_needed = size_string + sizeof(size_needed);
542 
543  if (FreeSize()>=size_needed) {
544  ::memcpy((fBufferIO+fCurrent),&size_string,sizeof(size_needed));
545  ::memcpy((fBufferIO+fCurrent+sizeof(size_needed)),data.data(),size_string);
546 
547  fCurrent += size_needed;
548  }
549  else fStatus = BaseBuffer::kFail ;
550  return (*this);
551 }
552 inline const BufferIO &BufferIO::operator >> (Char_t &data) const
553 {
554  if (FreeSize()>=sizeof(Char_t)) {
555  ::memcpy(&data,fBufferIO+fCurrent,sizeof(Char_t));
556  // data = fBufferIO[fCurrent];
557  fCurrent += sizeof(Char_t);
558  }
559  else fStatus = BaseBuffer::kFail ;
560  return (*this);
561 }
562 inline const BufferIO &BufferIO::operator >> (UChar_t &data) const
563 {
564  if (FreeSize()>=sizeof(Char_t)) {
565  ::memcpy(&data,fBufferIO+fCurrent,sizeof(UChar_t));
566  // data = (*((UChar_t *)(fBufferIO+fCurrent)));
567  fCurrent += sizeof(UChar_t);
568  }
569  else fStatus = BaseBuffer::kFail ;
570  return (*this);
571 }
572 inline const BufferIO &BufferIO::operator >> (Short_t &data) const
573 {
574  if (FreeSize()>=sizeof(Short_t)) {
575  ::memcpy(&data,fBufferIO+fCurrent,sizeof(Short_t));
576  // data = (*((Short_t *)(fBufferIO+fCurrent)));
577  fCurrent += sizeof(Short_t);
578  }
579  else fStatus = BaseBuffer::kFail ;
580  return (*this);
581 }
582 inline const BufferIO &BufferIO::operator >> (UShort_t &data) const
583 {
584  if (FreeSize()>=sizeof(Short_t)) {
585  ::memcpy(&data,fBufferIO+fCurrent,sizeof(UShort_t));
586  // data = (*((UShort_t *)(fBufferIO+fCurrent)));
587  fCurrent += sizeof(UShort_t);
588  }
589  else fStatus = BaseBuffer::kFail ;
590  return (*this);
591 }
592 inline const BufferIO & BufferIO::operator >> (Int_t &data) const
593 {
594  if (FreeSize()>=sizeof(Int_t)) {
595  ::memcpy(&data,fBufferIO+fCurrent,sizeof(Int_t));
596  // data = (*((Int_t *)(fBufferIO+fCurrent)));
597  fCurrent += sizeof(Int_t);
598  }
599  else fStatus = BaseBuffer::kFail ;
600  return (*this) ;
601 }
602 inline const BufferIO &BufferIO::operator >> (UInt_t &data) const
603 {
604  if (FreeSize()>=sizeof(Int_t)) {
605  ::memcpy(&data,fBufferIO+fCurrent,sizeof(UInt_t));
606  // data = (*((UInt_t *)(fBufferIO+fCurrent)));
607  fCurrent += sizeof(UInt_t);
608  }
609  else fStatus = BaseBuffer::kFail ;
610  return (*this);
611 }
612 inline const BufferIO &BufferIO::operator >> (Float_t &data) const
613 {
614  if (FreeSize()>=sizeof(Float_t)) {
615  ::memcpy(&data,fBufferIO+fCurrent,sizeof(Float_t));
616  // data = (*((Float_t *)(fBufferIO+fCurrent)));
617  fCurrent += sizeof(Float_t);
618  }
619  else fStatus = BaseBuffer::kFail ;
620  return (*this);
621 }
622 inline const BufferIO &BufferIO::operator >> (Double_t &data) const
623 {
624  if (FreeSize()>=sizeof(Double_t)) {
625  ::memcpy(&data,fBufferIO+fCurrent,sizeof(Double_t));
626  // data = (*((Double_t *)(fBufferIO+fCurrent)));
627  fCurrent += sizeof(Double_t);
628  }
629  else fStatus = BaseBuffer::kFail ;
630  return (*this);
631 }
632 inline const BufferIO & BufferIO::operator >> (Long_t &data) const
633 {
634  if (FreeSize()>=sizeof(Long64_t)) {
635  if (sizeof(Long_t) == 8)
636  ::memcpy(&data,fBufferIO+fCurrent,sizeof(Long_t));
637  else
638  ::memcpy(&data,fBufferIO+fCurrent+4,4);
639 
640  fCurrent += sizeof(Long64_t);
641  }
642  else fStatus = BaseBuffer::kFail ;
643  return (*this) ;
644 }
645 inline const BufferIO & BufferIO::operator >> (ULong_t &data) const
646 {
647  if (FreeSize()>=sizeof(ULong64_t)) {
648  if (sizeof(ULong_t) == 8)
649  ::memcpy(&data,fBufferIO+fCurrent,sizeof(ULong_t));
650  else
651  ::memcpy(&data,fBufferIO+fCurrent+4,4);
652 
653  fCurrent += sizeof(ULong64_t);
654  }
655  else fStatus = BaseBuffer::kFail ;
656  return (*this) ;
657 }
658 
659 inline const BufferIO & BufferIO::operator >> (Long64_t &data) const
660 {
661  if (FreeSize()>=sizeof(Long64_t)) {
662  ::memcpy(&data,fBufferIO+fCurrent,sizeof(Long64_t));
663  // data = (*((Long64_t *)(fBufferIO+fCurrent)));
664  fCurrent += sizeof(Long64_t);
665  }
666  else fStatus = BaseBuffer::kFail ;
667  return (*this) ;
668 }
669 inline const BufferIO & BufferIO::operator >> (ULong64_t &data) const
670 {
671  if (FreeSize()>=sizeof(ULong64_t)) {
672  ::memcpy(&data,fBufferIO+fCurrent,sizeof(ULong64_t));
673  // data = (*((ULong64_t *)(fBufferIO+fCurrent)));
674  fCurrent += sizeof(ULong64_t);
675  }
676  else fStatus = BaseBuffer::kFail ;
677  return (*this) ;
678 }
679 inline const BufferIO &BufferIO::operator >> (std::string &data) const
680 {
681  UShort_t size_string;
682  if ( FreeSize()>=sizeof(size_string) ){
683  ::memcpy(&size_string,fBufferIO+fCurrent,sizeof(size_string));
684  if (FreeSize()>=size_string)
685  {
686  data.assign(fBufferIO+fCurrent+sizeof(size_string),size_string);
687  fCurrent += ( size_string + sizeof(size_string) );
688  }
689  else fStatus = BaseBuffer::kFail ;
690  }
691  else fStatus = BaseBuffer::kFail ;
692  return (*this);
693 }
694 inline UInt_t BufferIO::Export(Char_t *output, UInt_t size) const
695 {
696  UInt_t bread = size;
697 
698  if (FreeSize()>=bread)
699  { BaseBuffer::Copy(fBufferIO+fCurrent,output,bread); fCurrent += bread; }
700  else { fStatus = BaseBuffer::kFail ; bread = 0u ; }
701 
702  return bread;
703 }
704 inline UInt_t BufferIO::Export(UShort_t *output, UInt_t size) const
705 {
706  UInt_t bread = size*sizeof(UShort_t);
707 
708  if (FreeSize()>=bread)
709  { BaseBuffer::Copy(fBufferIO+fCurrent,output,bread); fCurrent += bread; }
710  else { fStatus = BaseBuffer::kFail ; bread = 0u ; }
711 
712  return bread;
713 }
714 inline UInt_t BufferIO::Export(Short_t *output, UInt_t size) const
715 {
716  UInt_t bread = size*sizeof(Short_t);
717 
718  if (FreeSize()>=bread)
719  { BaseBuffer::Copy(fBufferIO+fCurrent,output,bread); fCurrent += bread; }
720  else { fStatus = BaseBuffer::kFail ; bread = 0u ; }
721 
722  return bread;
723 }
724 inline UInt_t BufferIO::Export(UInt_t *output, UInt_t size) const
725 {
726  UInt_t bread = size*sizeof(UInt_t);
727 
728  if (FreeSize()>=bread)
729  { BaseBuffer::Copy(fBufferIO+fCurrent,output,bread); fCurrent += bread; }
730  else { fStatus = BaseBuffer::kFail ; bread = 0u ; }
731 
732  return bread;
733 }
734 inline UInt_t BufferIO::Export(Int_t *output, UInt_t size) const
735 {
736  UInt_t bread = size*sizeof(Int_t);
737 
738  if (FreeSize()>=bread)
739  { BaseBuffer::Copy(fBufferIO+fCurrent,output,bread); fCurrent += bread; }
740  else { fStatus = BaseBuffer::kFail ; bread = 0u ; }
741 
742  return bread;
743 }
744 inline UInt_t BufferIO::Export(Float_t *output, UInt_t size) const
745 {
746  UInt_t bread = size*sizeof(Float_t);
747 
748  if (FreeSize()>=bread)
749  { BaseBuffer::Copy(fBufferIO+fCurrent,output,bread); fCurrent += bread; }
750  else { fStatus = BaseBuffer::kFail ; bread = 0u ; }
751 
752  return bread;
753 }
754 inline UInt_t BufferIO::Export(Double_t *output, UInt_t size) const
755 {
756  UInt_t bread = size*sizeof(Double_t);
757 
758  if (FreeSize()>=bread)
759  { BaseBuffer::Copy(fBufferIO+fCurrent,output,bread); fCurrent += bread; }
760  else { fStatus = BaseBuffer::kFail ; bread = 0u ; }
761 
762  return bread;
763 }
764 inline UInt_t BufferIO::FillWith(Char_t c, UInt_t how_many)
765 {
766  UInt_t bwritten;
767  how_many > FreeSize() ? bwritten = FreeSize() : bwritten = how_many ;
768 
769  ::memset(fBufferIO+fCurrent,c,bwritten);
770  fCurrent += bwritten;
771 
772  return bwritten;
773 }
774 inline UInt_t BufferIO::Import(const UShort_t *input, UInt_t size)
775 {
776  UInt_t bwritten = size*sizeof(UShort_t);
777 
778  if (FreeSize()>=bwritten)
779  { BaseBuffer::Copy(input,fBufferIO+fCurrent,bwritten); fCurrent += bwritten; }
780  else { fStatus = BaseBuffer::kFail ; bwritten = 0u ; }
781 
782  return bwritten;
783 }
784 inline UInt_t BufferIO::Import(const Short_t *input, UInt_t size)
785 {
786  UInt_t bwritten = size*sizeof(Short_t);
787 
788  if (FreeSize()>=bwritten)
789  { BaseBuffer::Copy(input,fBufferIO+fCurrent,bwritten); fCurrent += bwritten; }
790  else { fStatus = BaseBuffer::kFail ; bwritten = 0u ; }
791 
792  return bwritten;
793 }
794 inline UInt_t BufferIO::Import(const UInt_t *input, UInt_t size)
795 {
796  UInt_t bwritten = size*sizeof(UInt_t);
797 
798  if (FreeSize()>=bwritten)
799  { BaseBuffer::Copy(input,fBufferIO+fCurrent,bwritten); fCurrent += bwritten; }
800  else { fStatus = BaseBuffer::kFail ; bwritten = 0u ; }
801 
802  return bwritten;
803 }
804 inline UInt_t BufferIO::Import(const Int_t *input, UInt_t size)
805 {
806  UInt_t bwritten = size*sizeof(Int_t);
807 
808  if (FreeSize()>=bwritten)
809  { BaseBuffer::Copy(input,fBufferIO+fCurrent,bwritten); fCurrent += bwritten; }
810  else { fStatus = BaseBuffer::kFail ; bwritten = 0u ; }
811 
812  return bwritten;
813 }
814 inline UInt_t BufferIO::Import(const Float_t *input, UInt_t size)
815 {
816  UInt_t bwritten = size*sizeof(Float_t);
817 
818  if (FreeSize()>=bwritten)
819  { BaseBuffer::Copy(input,fBufferIO+fCurrent,bwritten); fCurrent += bwritten; }
820  else { fStatus = BaseBuffer::kFail ; bwritten = 0u ; }
821 
822  return bwritten;
823 }
824 inline UInt_t BufferIO::Import(const Double_t *input, UInt_t size)
825 {
826  UInt_t bwritten = size*sizeof(Double_t);
827 
828  if (FreeSize()>=bwritten)
829  { BaseBuffer::Copy(input,fBufferIO+fCurrent,bwritten); fCurrent += bwritten; }
830  else { fStatus = BaseBuffer::kFail ; bwritten = 0u ; }
831 
832  return bwritten;
833 }
834 
835 // inline BufferIO members //////////////////////////
836 
838 
843 class EndianBufferIO : public BufferIO
844 {
845 public:
846  EndianBufferIO(UInt_t s = aKByte);
847  virtual ~EndianBufferIO();
848 
849  virtual BufferIO &operator << (Char_t) ;
850  virtual BufferIO &operator << (UChar_t);
851  virtual BufferIO &operator << (Short_t);
852  virtual BufferIO &operator << (UShort_t);
853  virtual BufferIO &operator << (Int_t);
854  virtual BufferIO &operator << (UInt_t);
855  virtual BufferIO &operator << (Float_t);
856  virtual BufferIO &operator << (Double_t);
857  virtual BufferIO &operator << (Long64_t);
858  virtual BufferIO &operator << (ULong64_t);
859  virtual BufferIO &operator << (Long_t);
860  virtual BufferIO &operator << (ULong_t);
861 
862  virtual BufferIO &operator << (std::string);
863 
864  virtual const BufferIO &operator >> (Char_t &) const;
865  virtual const BufferIO &operator >> (UChar_t &) const;
866  virtual const BufferIO &operator >> (Short_t &) const;
867  virtual const BufferIO &operator >> (UShort_t &) const;
868  virtual const BufferIO &operator >> (Int_t &) const;
869  virtual const BufferIO &operator >> (UInt_t &) const;
870  virtual const BufferIO &operator >> (Float_t &) const;
871  virtual const BufferIO &operator >> (Double_t &) const;
872  virtual const BufferIO &operator >> (Long64_t &) const;
873  virtual const BufferIO &operator >> (ULong64_t &) const;
874  virtual const BufferIO &operator >> (Long_t &) const;
875  virtual const BufferIO &operator >> (ULong_t &) const;
876 
877  virtual const BufferIO &operator>> (std::string &) const;
878 
879 };
880 // inline EndianBufferIO members
882  { return BufferIO::operator << (data) ;}
884  { return BufferIO::operator << (data); }
886 {
887  if (FreeSize()>=sizeof(Short_t)) {
889  fCurrent += sizeof(Short_t);
890  }
891  else fStatus = BaseBuffer::kFail ;
892  return (*this);
893 }
895 {
896  if (FreeSize()>=sizeof(UShort_t)) {
898  fCurrent += sizeof(UShort_t);
899  }
900  else fStatus = BaseBuffer::kFail ;
901  return (*this);
902 }
904 {
905  if (FreeSize()>=sizeof(Int_t)) {
907  fCurrent += sizeof(Int_t);
908  }
909  else fStatus = BaseBuffer::kFail ;
910  return (*this);
911 }
913 {
914  if (FreeSize()>=sizeof(UInt_t)) {
916  fCurrent += sizeof(UInt_t);
917  }
918  else fStatus = BaseBuffer::kFail ;
919  return (*this);
920 }
922 {
923  if (FreeSize()>=sizeof(Float_t)) {
925  fCurrent += sizeof(Float_t);
926  }
927  else fStatus = BaseBuffer::kFail ;
928  return (*this);
929 }
930 inline BufferIO &EndianBufferIO::operator << (Double_t data)
931 {
932  if (FreeSize()>=sizeof(Double_t)){
934  fCurrent += sizeof(Double_t);
935  }
936  else fStatus = BaseBuffer::kFail ;
937  return (*this);
938 }
940 {
941  if (FreeSize()>=sizeof(Long64_t)) {
943  fCurrent += sizeof(Long64_t);
944  }
945  else fStatus = BaseBuffer::kFail ;
946  return (*this);
947 }
948 inline BufferIO &EndianBufferIO::operator << (ULong64_t data)
949 {
950  if (FreeSize()>=sizeof(ULong64_t)){
952  fCurrent += sizeof(ULong64_t);
953  }
954  else fStatus = BaseBuffer::kFail ;
955  return (*this);
956 }
958 {
959  if (FreeSize()>=sizeof(Long64_t)) {
961  fCurrent += sizeof(Long64_t);
962  }
963  else fStatus = BaseBuffer::kFail ;
964  return (*this);
965 }
967 {
968  if (FreeSize()>=sizeof(ULong64_t)){
970  fCurrent += sizeof(ULong64_t);
971  }
972  else fStatus = BaseBuffer::kFail ;
973  return (*this);
974 }
975 inline BufferIO &EndianBufferIO::operator << (std::string data)
976 {
977  UShort_t size_string = (UShort_t)data.size();
978  UShort_t size_needed = size_string + sizeof(size_needed);
979 
980  if (FreeSize()>=size_needed) {
981  BaseBuffer::Swap(size_string,fBufferIO+fCurrent);
982  ::memcpy((fBufferIO+fCurrent+sizeof(size_needed)),data.data(),size_string);
983 
984  fCurrent += size_needed;
985  }
986  else fStatus = BaseBuffer::kFail ;
987  return (*this);
988 }
989 inline const BufferIO &EndianBufferIO::operator >> (Char_t &data) const
990 {
991  return BufferIO::operator >> (data) ;
992 }
993 inline const BufferIO &EndianBufferIO::operator >> (UChar_t &data) const
994 {
995  return BufferIO::operator >> (data);
996 }
997 inline const BufferIO &EndianBufferIO::operator >> (Short_t &data) const
998 {
999  if (FreeSize()>=sizeof(Short_t)){
1001  fCurrent += sizeof(Short_t);
1002  }
1003  else fStatus = BaseBuffer::kFail ;
1004  return (*this);
1005 }
1006 inline const BufferIO &EndianBufferIO::operator >> (UShort_t &data) const
1007 {
1008  if (FreeSize()>=sizeof(UShort_t)){
1010  fCurrent += sizeof(UShort_t);
1011  }
1012  else fStatus = BaseBuffer::kFail ;
1013  return (*this);
1014 }
1015 inline const BufferIO &EndianBufferIO::operator >> (Int_t &data) const
1016 {
1017  if (FreeSize()>=sizeof(Int_t)){
1019  fCurrent += sizeof(Int_t);
1020  }
1021  else fStatus = BaseBuffer::kFail ;
1022  return (*this);
1023 }
1024 inline const BufferIO &EndianBufferIO::operator >> (UInt_t &data) const
1025 {
1026  if (FreeSize()>=sizeof(UInt_t)){
1028  fCurrent += sizeof(UInt_t);
1029  }
1030  else fStatus = BaseBuffer::kFail ;
1031  return (*this);
1032 }
1033 
1034 inline const BufferIO &EndianBufferIO::operator >> (Long64_t &data) const
1035 {
1036  if (FreeSize()>=sizeof(Long64_t)){
1038  fCurrent += sizeof(Long64_t);
1039  }
1040  else fStatus = BaseBuffer::kFail ;
1041  return (*this);
1042 }
1043 inline const BufferIO &EndianBufferIO::operator >> (ULong64_t &data) const
1044 {
1045  if (FreeSize()>=sizeof(ULong64_t)){
1047  fCurrent += sizeof(ULong64_t);
1048  }
1049  else fStatus = BaseBuffer::kFail ;
1050  return (*this);
1051 }
1052 
1053 inline const BufferIO &EndianBufferIO::operator >> (Float_t &data) const
1054 {
1055  if (FreeSize()>=sizeof(Float_t)){
1057  fCurrent += sizeof(Float_t);
1058  }
1059  else fStatus = BaseBuffer::kFail ;
1060  return (*this);
1061 }
1062 inline const BufferIO &EndianBufferIO::operator >> (Double_t &data) const
1063 {
1064  if (FreeSize()>=sizeof(Double_t)){
1066  fCurrent += sizeof(Double_t);
1067  }
1068  else fStatus = BaseBuffer::kFail ;
1069  return (*this);
1070 }
1071 inline const BufferIO &EndianBufferIO::operator >> (Long_t &data) const
1072 {
1073  if (FreeSize()>=sizeof(Long64_t)){
1075  fCurrent += sizeof(Long64_t);
1076  }
1077  else fStatus = BaseBuffer::kFail ;
1078  return (*this);
1079 }
1080 inline const BufferIO &EndianBufferIO::operator >> (ULong_t &data) const
1081 {
1082  if (FreeSize()>=sizeof(ULong64_t)){
1084  fCurrent += sizeof(ULong64_t);
1085  }
1086  else fStatus = BaseBuffer::kFail ;
1087  return (*this);
1088 }
1089 inline const BufferIO &EndianBufferIO::operator>> (std::string &data) const
1090 {
1091  UShort_t size_string;
1092 
1093  if (FreeSize()>=sizeof(size_string)){
1094  BaseBuffer::Swap(fBufferIO+fCurrent,size_string);
1095  if (FreeSize()>=size_string)
1096  {
1097  data.assign(fBufferIO+fCurrent+sizeof(size_string),size_string);
1098  fCurrent += ( size_string + sizeof(size_string) );
1099  }
1100  else fStatus = BaseBuffer::kFail ;
1101  }
1102  else fStatus = BaseBuffer::kFail ;
1103  return (*this);
1104 }
1105 
1106 }; // ADF namespace
1107 
1108 #endif
virtual Bool_t Reserve(UInt_t size)
to reserve a given size (from the current position) to be sure one are able to write something ...
Definition: BufferIO.cpp:199
void SetStatus(BufferIO::EStatus s=BaseBuffer::kGood)
Definition: BufferIO.h:106
BufferIO::EStatus GetStatus() const
Definition: BufferIO.h:109
Char_t * fBufferIO
current buffer in which data are read/written
Definition: BufferIO.h:73
Char_t * CurrentAddress()
for classes that needs it to write directly data into it.
Definition: BufferIO.h:101
virtual Bool_t Link(const Char_t *from, UInt_t from_size)
Link an external buffer to this class.
Definition: BufferIO.cpp:214
virtual BufferIO & operator<<(Char_t)
Definition: BufferIO.h:394
virtual void Reset()
Reset means set all elements to 0 and the current position is 0.
Definition: BufferIO.cpp:109
BufferIO(UInt_t s=aByte)
Default size for a BufferIO is one byte just because it could be used only with an external buffer...
Definition: BufferIO.cpp:29
static void Swap(Short_t, Char_t *)
the Swap members
Definition: BaseBuffer.h:256
const UInt_t kMaxUInt_t
Definition: ADFConfig.h:100
Bool_t IsAnOffset(const Char_t *off, UInt_t &pos) const
check if this address belongs to this buffer
Definition: BufferIO.cpp:142
virtual Bool_t IsLinked()
check if this is linked or not
Definition: BufferIO.h:160
A Endianbuffer is used to read/write raw data buffers from/on files.
Definition: BufferIO.h:843
virtual Char_t * Unlink()
Unlink the external buffer to this class.
Definition: BufferIO.cpp:373
virtual UInt_t FillWith(Char_t c, UInt_t how_many)
add the same character how_many times from the current position
Definition: BufferIO.h:764
UInt_t fRealSize
Real size of the current buffer.
Definition: BufferIO.h:77
UInt_t Offset() const
it returns the current position in the buffer
Definition: BufferIO.h:240
UInt_t Size() const
it returns the maximum number of bytes in this buffer
Definition: BufferIO.h:220
const UInt_t aKByte
Definition: BaseBuffer.h:35
static Bool_t Copy(const BufferIO &from, BufferIO &to, UInt_t size, UInt_t off_from=0u)
copy from a buffer to another one
Definition: BufferIO.h:172
UInt_t fCurrent
current position in the buffer (mutable so that reading are allowed for constant) ...
Definition: BufferIO.h:80
Base class for a buffer.
Definition: BaseBuffer.h:48
Base class for a CompositeFrame.
UInt_t FreeSize() const
it returns the number of free bytes to the end
Definition: BufferIO.h:236
virtual const BufferIO & operator>>(Char_t &) const
Definition: BufferIO.h:552
void SetCurrent(const char= 'i')
to switch between inner and outer
Definition: BufferIO.cpp:47
const Char_t * GetAddress() const
Pointer to the current underlying array of bytes.
Definition: BufferIO.h:216
virtual UInt_t Export(Char_t *, UInt_t) const
Export this buffer to an array.
Definition: BufferIO.h:694
void AllocInner(UInt_t)
Definition: BufferIO.cpp:78
static void Copy(const void *from, void *to, Int_t size)
copy the content from -> to
Definition: BaseBuffer.h:172
EndianBufferIO(UInt_t s=aKByte)
Definition: BufferIO.cpp:384
virtual Bool_t Copy(const Char_t *from, UInt_t from_size)
copy an external buffer to this.
Definition: BufferIO.cpp:248
static BufferIO * New(BaseBuffer::EEndian e, UInt_t s=aByte)
return the right buffer taking Into account the endian argument compared to the underlying endian sys...
Definition: BufferIO.cpp:94
static Bool_t Copy(const BufferIO &from, BufferIO &to)
copy a buffer to another one
Definition: BufferIO.h:204
const UInt_t aByte
Definition: BaseBuffer.h:34
virtual Bool_t Expand(UInt_t new_size)
Expand the size of the current buffer.
Definition: BufferIO.cpp:162
UInt_t SetEffectiveSize(UInt_t size=kMaxUInt_t)
in case the buffer is partly filled and you would like to read it again
Definition: BufferIO.cpp:152
void SetEndian(BaseBuffer::EEndian e)
Definition: BufferIO.h:84
BaseBuffer::EEndian GetEndian() const
Definition: BufferIO.h:112
UInt_t Import(const Char_t *from, UInt_t size_ext_buf)
Import the given array in this buffer.
Definition: BufferIO.cpp:298
virtual const BufferIO & operator>>(Char_t &) const
Definition: BufferIO.h:989
virtual ~EndianBufferIO()
Definition: BufferIO.cpp:391
EStatus
Status for this buffer.
Definition: BaseBuffer.h:57
Bool_t IsEndian(BaseBuffer::EEndian e) const
Definition: BufferIO.h:114
virtual void FastReset()
Definition: BufferIO.cpp:117
Char_t * Address()
for classes that needs it to write directly data into it.
Definition: BufferIO.h:98
Bool_t IsStatus(BufferIO::EStatus s) const
Definition: BufferIO.h:104
EStatus fStatus
current status
Definition: BufferIO.h:57
const Int_t size
Definition: BenchIO.C:24
UInt_t fSize
effective size of the current buffer
Definition: BufferIO.h:75
virtual BufferIO & operator<<(Char_t)
Definition: BufferIO.h:881
EEndian fEndian
current endian
Definition: BufferIO.h:59
virtual ~BufferIO()
Definition: BufferIO.cpp:67
UInt_t SetOffset(UInt_t off=0u) const
change the current position.
Definition: BufferIO.cpp:122