Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
MethodVar.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 18/2/2016
2
4//
5// MethodVar
6//
7// A "global variable" referencing a class member function call
8//
10
11#include "MethodVar.h"
12#include "THaVar.h"
13#include "TError.h"
14#include "TMethodCall.h"
15#include <cstring> // for memcpy
16#include <cassert>
17#include <cmath>
18#include <limits>
19
20using namespace std;
21
22namespace Podd {
23
24//_____________________________________________________________________________
25MethodVar::MethodVar( THaVar* pvar, const void* addr,
26 VarType type, TMethodCall* method )
27 : Variable(pvar,addr,type), fMethod(method), fData(0)
28{
29 // Constructor
30 assert( fMethod );
31
32 if( !VerifyNonArrayName(GetName()) ) {
33 fValueP = nullptr;
34 return;
35 }
36}
37
38//_____________________________________________________________________________
40{
41 // Destructor
42
43 delete fMethod;
44}
45
46//_____________________________________________________________________________
47const void* MethodVar::GetDataPointer( Int_t i ) const
48{
49 // Get pointer to data via method call on the object pointed to by fValueP.
50 // Requesting "elements" other than i==0 is not allowed.
51
52 const char* const here = "GetDataPointer()";
53
54 assert( fValueP );
55 assert( fMethod );
56
57 if( i != 0 ) {
58 fSelf->Error( here, "Index out of range, variable %s, index %d", GetName(), i );
59 return nullptr;
60 }
61
62 return GetDataPointer(fValueP);
63}
64
65//_____________________________________________________________________________
66const void* MethodVar::GetDataPointer( const void* obj ) const
67{
68 // Make the method call on the object pointed to by 'obj'
69
70 void* pobj = const_cast<void*>(obj); // TMethodCall wants a non-const object...
71
72 if( IsFloat() ) {
73 // Floating-point data
75 fMethod->Execute( pobj, result );
76 switch( fType ) {
77 case kDouble:
78 fData = result;
79 break;
80 case kFloat:
81 {
82 // The data here must fit without overflow, otherwise the interpreter
83 // lied to us when it gave us the function return type
84 assert( fabs(result) <= numeric_limits<float>::max() );
85
86 // The conversion could be done in a single assignment,
87 //*reinterpret_cast<Float_t*>(&fData) = result;
88 //but it's more readable and perhaps more portable this way
89 Float_t resultF = result;
90 memcpy( &fData, &resultF, sizeof(resultF) );
91 }
92 break;
93 default:
94 assert(false); // ill-constructed object (error in THaVarList::DefineByRTTI)
95 }
96 return &fData;
97 }
98 else {
99 // Integer data
100 Long_t result; // TMethodCall really wants Long_t, not Long64_t
101 fMethod->Execute( pobj, result );
102 switch( fType ) {
103 case kLong:
104 case kULong:
105 memcpy( &fData, &result, sizeof(result) );
106 break;
107 case kInt:
108 case kUInt:
109 {
110 Int_t resultI = result;
111 memcpy( &fData, &resultI, sizeof(resultI) );
112 }
113 break;
114 case kShort:
115 case kUShort:
116 {
117 Short_t resultS = result;
118 memcpy( &fData, &resultS, sizeof(resultS) );
119 }
120 break;
121 case kChar:
122 case kUChar:
123 {
124 Char_t resultC = result;
125 memcpy( &fData, &resultC, sizeof(resultC) );
126 }
127 break;
128 default:
129 assert(false); // ill-constructed object (error in THaVarList::DefineByRTTI)
130 }
131 return &fData;
132 }
133 // Not reached
134 return nullptr;
135}
136
137//_____________________________________________________________________________
139{
140 // Data are basic (POD variable or array)
141
142 return false;
143}
144
145//_____________________________________________________________________________
146
147}// namespace Podd
int Int_t
long Long_t
bool Bool_t
char Char_t
float Float_t
short Short_t
double Double_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
static const char *const here
Definition THaVar.cxx:64
Double_t fData
Definition MethodVar.h:31
virtual ~MethodVar()
Definition MethodVar.cxx:39
virtual Bool_t IsBasic() const
virtual const void * GetDataPointer(Int_t i=0) const
Definition MethodVar.cxx:47
TMethodCall * fMethod
Definition MethodVar.h:29
MethodVar(THaVar *pvar, const void *addr, VarType type, TMethodCall *method)
Definition MethodVar.cxx:25
virtual Bool_t IsFloat() const
Definition Variable.cxx:441
const void * fValueP
Definition Variable.h:60
Bool_t VerifyNonArrayName(const char *name) const
Definition Variable.cxx:38
const char * GetName() const
Definition Variable.cxx:56
THaVar * fSelf
Definition Variable.h:59
VarType fType
Definition Variable.h:61
void Execute()
virtual void Error(const char *method, const char *msgfmt,...) const
Expr< UnaryOp< Fabs< T >, Expr< A, T, D, D2, R >, T >, T, D, D2, R > fabs(const Expr< A, T, D, D2, R > &rhs)
STL namespace.