Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaArrayString.h
Go to the documentation of this file.
1#ifndef Podd_THaArrayString_h_
2#define Podd_THaArrayString_h_
3
5//
6// THaArrayString
7//
9
10#include "TString.h"
11#include <cassert>
12
14
15public:
18
19 THaArrayString() : fNdim(0), fDim(nullptr), fLen(-1), fStatus(kNotinit) {}
20 THaArrayString( const char* string )
21 : fName(string), fNdim(0), fDim(nullptr), fLen(-1), fStatus(kNotinit)
22 { Parse(); }
25 THaArrayString& operator=( const char* rhs ) { Parse( rhs ); return *this; }
26 virtual ~THaArrayString() { if( fNdim>kMaxA ) delete [] fDim; }
27
28 operator const char*() const { return fName.Data(); }
29 operator const TString&() const { return fName; }
30 Int_t operator[](Int_t i) const;
31 bool operator!() const { return IsError(); }
32
33 const Int_t* GetDim() const;
34 Int_t GetLen() const { return fLen; }
35 const char* GetName() const { return fName.Data(); }
36 Int_t GetNdim() const { return fNdim; }
37 ULong_t Hash() const { return fName.Hash(); }
38 Bool_t IsArray() const { return (fNdim > 0); }
39 Bool_t IsError() const { return (fStatus != kOK); }
40 virtual Int_t Parse( const char* string="" );
41 virtual void Print( Option_t* opt="" ) const;
42 EStatus Status() const { return fStatus; }
43
44protected:
45#ifdef R__B64
46 static const Int_t kMaxA = 2;
47#else
48 static const Int_t kMaxA = 1;
49#endif
50 TString fName; //Variable name
51 Int_t fNdim; //Number of array dimensions (0=scalar)
52 union {
53 Int_t* fDim; //Dimensions if fNdim > kMaxA
54 Int_t fDimA[kMaxA]; //Dimensions if fNdim <= kMaxA
55 };
56 Int_t fLen; //Length of array (product of all dimensions)
57 EStatus fStatus; //Status of Parse()
58
59 ClassDef(THaArrayString,0) //Parser for variable names with support for arrays
60};
61
62//__________________ inlines __________________________________________________
63inline
65{
66 // Return i-th array dimension
67 assert( i >= 0 && i < fNdim );
68 if( fNdim>kMaxA ) {
69 assert( fDim );
70 return fDim[i];
71 } else
72 return fDimA[i];
73}
74
75//_____________________________________________________________________________
76inline
78{
79 if( fNdim == 0 )
80 return 0;
81 else if( fNdim>kMaxA )
82 return fDim;
83 else
84 return fDimA;
85}
86
87#endif
int Int_t
unsigned long ULong_t
bool Bool_t
const char Option_t
#define ClassDef(name, id)
EStatus Status() const
virtual ~THaArrayString()
virtual void Print(Option_t *opt="") const
Bool_t IsArray() const
const Int_t * GetDim() const
Int_t fDimA[kMaxA]
THaArrayString(const char *string)
ULong_t Hash() const
static const Int_t kMaxA
Bool_t IsError() const
bool operator!() const
THaArrayString & operator=(const char *rhs)
Int_t GetNdim() const
virtual Int_t Parse(const char *string="")
const char * GetName() const
Int_t GetLen() const
Int_t operator[](Int_t i) const
THaArrayString & operator=(const THaArrayString &)
const char * Data() const
UInt_t Hash(ECaseCompare cmp=kExact) const