Belle II Software development
NSMVar Class Reference
Inheritance diagram for NSMVar:
Serializable

Public Types

enum  Type {
  NONE = 0 ,
  INT ,
  FLOAT ,
  TEXT
}
 

Public Member Functions

 NSMVar (const std::string &name, Type type, int len, const void *value)
 
 NSMVar (const std::string &name, const std::string &value)
 
 NSMVar (const std::string &name, int value)
 
 NSMVar (const std::string &name, float value)
 
 NSMVar (const std::string &name, int len, int *value)
 
 NSMVar (const std::string &name, int len, float *value)
 
 NSMVar (const std::string &name, const std::vector< int > &value)
 
 NSMVar (const std::string &name, const std::vector< float > &value)
 
 NSMVar (const std::string &name)
 
 NSMVar (const NSMVar &var)
 
const NSMVaroperator= (const NSMVar &var)
 
const NSMVaroperator= (int val)
 
const NSMVaroperator= (float val)
 
const NSMVaroperator= (const std::string &val)
 
const NSMVaroperator= (const std::vector< int > &val)
 
const NSMVaroperator= (const std::vector< float > &val)
 
const NSMVaroperator>> (int &val) const
 
const NSMVaroperator>> (float &val) const
 
const NSMVaroperator>> (std::string &val) const
 
const NSMVaroperator>> (std::vector< int > &val) const
 
const NSMVaroperator>> (std::vector< float > &val) const
 
void setNode (const std::string &node)
 
void setName (const std::string &name)
 
const void * get () const
 
void * get ()
 
int size () const
 
const std::string & getNode () const
 
const std::string & getName () const
 
Type getType () const
 
const char * getTypeLabel () const
 
int getLength () const
 
int getInt () const
 
float getFloat () const
 
const char * getText () const
 
int getInt (int i) const
 
float getFloat (int i) const
 
int getId () const
 
void setId (int id)
 
void setDate (int date)
 
void setDate (const Date &date)
 
int getDate () const
 
void readObject (Reader &) override
 
void writeObject (Writer &) const override
 
void copy (const std::string &name, Type type, int len, const void *value, int id=0, int date=0)
 

Static Public Attributes

static const NSMVar NOVALUE
 

Private Attributes

void * m_value
 
std::string m_node
 
std::string m_name
 
Type m_type
 
int m_len
 
int m_id
 
int m_date
 

Detailed Description

Definition at line 23 of file NSMVar.h.

Member Enumeration Documentation

◆ Type

enum Type

Definition at line 26 of file NSMVar.h.

26 {
27 NONE = 0,
28 INT,
29 FLOAT,
30 TEXT,
31 };

Constructor & Destructor Documentation

◆ NSMVar() [1/11]

NSMVar ( )
inline

Definition at line 37 of file NSMVar.h.

37 : m_value(NULL), m_name(), m_type(NONE), m_len(0)
38 {
39 setDate(Date());
40 }

◆ NSMVar() [2/11]

NSMVar ( const std::string &  name,
Type  type,
int  len,
const void *  value 
)
inline

Definition at line 41 of file NSMVar.h.

42 : m_value(NULL)
43 {
44 copy(name, type, len, value);
45 }

◆ NSMVar() [3/11]

NSMVar ( const std::string &  name,
const std::string &  value 
)
inline

Definition at line 46 of file NSMVar.h.

47 : m_value(NULL)
48 {
49 copy(name, TEXT, value.size(), value.c_str());
50 }

◆ NSMVar() [4/11]

NSMVar ( const std::string &  name,
int  value 
)
inline

Definition at line 51 of file NSMVar.h.

52 : m_value(NULL)
53 {
54 copy(name, INT, 0, &value);
55 }

◆ NSMVar() [5/11]

NSMVar ( const std::string &  name,
float  value 
)
inline

Definition at line 56 of file NSMVar.h.

57 : m_value(NULL)
58 {
59 copy(name, FLOAT, 0, &value);
60 }

◆ NSMVar() [6/11]

NSMVar ( const std::string &  name,
int  len,
int *  value 
)
inline

Definition at line 61 of file NSMVar.h.

62 : m_value(NULL)
63 {
64 copy(name, INT, len, value);
65 }

◆ NSMVar() [7/11]

NSMVar ( const std::string &  name,
int  len,
float *  value 
)
inline

Definition at line 66 of file NSMVar.h.

67 : m_value(NULL)
68 {
69 copy(name, FLOAT, len, value);
70 }

◆ NSMVar() [8/11]

NSMVar ( const std::string &  name,
const std::vector< int > &  value 
)

Definition at line 18 of file NSMVar.cc.

19 : m_value(NULL)
20{
21 int* v = (int*)malloc(value.size() * sizeof(int));
22 for (size_t i = 0; i < value.size(); i++)
23 v[i] = value[i];
24 m_name = name;
25 m_type = INT;
26 m_len = value.size();
27 m_value = v;
28 m_id = 0;
29 m_date = Date().get();
30}

◆ NSMVar() [9/11]

NSMVar ( const std::string &  name,
const std::vector< float > &  value 
)

Definition at line 32 of file NSMVar.cc.

33 : m_value(NULL)
34{
35 float* v = (float*)malloc(value.size() * sizeof(float));
36 for (size_t i = 0; i < value.size(); i++)
37 v[i] = value[i];
38 m_name = name;
39 m_type = INT;
40 m_len = value.size();
41 m_value = v;
42 m_id = 0;
43 m_date = Date().get();
44}

◆ NSMVar() [10/11]

NSMVar ( const std::string &  name)
inline

Definition at line 73 of file NSMVar.h.

73: m_value(NULL), m_name(name), m_type(NONE), m_len(0) {}

◆ NSMVar() [11/11]

NSMVar ( const NSMVar var)
inline

Definition at line 74 of file NSMVar.h.

74: m_value(NULL) { *this = var; }

◆ ~NSMVar()

~NSMVar ( )

Definition at line 122 of file NSMVar.cc.

123{
124 if (m_value) free(m_value);
125}

Member Function Documentation

◆ copy()

void copy ( const std::string &  name,
Type  type,
int  len,
const void *  value,
int  id = 0,
int  date = 0 
)

Definition at line 100 of file NSMVar.cc.

103{
104 if (m_value) free(m_value);
105 m_value = NULL;
106 m_name = name;
107 m_type = type;
108 m_len = len;
109 m_id = id;
110 m_date = (date > 0) ? date : Date().get();
111 int s = size();
112 if (s > 0) {
113 m_value = malloc(s);
114 memcpy(m_value, value, s);
115 } else {
116 m_type = NONE;
117 m_len = 0;
118 m_value = NULL;
119 }
120}

◆ get() [1/2]

void * get ( )
inline

Definition at line 116 of file NSMVar.h.

116{ return m_value; }

◆ get() [2/2]

const void * get ( ) const
inline

Definition at line 115 of file NSMVar.h.

115{ return m_value; }

◆ getDate()

int getDate ( ) const
inline

Definition at line 132 of file NSMVar.h.

132{ return m_date; }

◆ getFloat() [1/2]

float getFloat ( ) const

Definition at line 201 of file NSMVar.cc.

202{
203 return (m_type == FLOAT && m_len == 0) ? *(float*)m_value : 0;
204}

◆ getFloat() [2/2]

float getFloat ( int  i) const

Definition at line 216 of file NSMVar.cc.

217{
218 return (m_type == FLOAT && i < m_len) ? ((float*)m_value)[i] : 0;
219}

◆ getId()

int getId ( ) const
inline

Definition at line 128 of file NSMVar.h.

128{ return m_id; }

◆ getInt() [1/2]

int getInt ( ) const

Definition at line 196 of file NSMVar.cc.

197{
198 return (m_type == INT&& m_len == 0) ? *(int*)m_value : 0;
199}

◆ getInt() [2/2]

int getInt ( int  i) const

Definition at line 211 of file NSMVar.cc.

212{
213 return (m_type == INT&& i < m_len) ? ((int*)m_value)[i] : 0;
214}

◆ getLength()

int getLength ( ) const
inline

Definition at line 122 of file NSMVar.h.

122{ return m_len; }

◆ getName()

const std::string & getName ( ) const
inline

Definition at line 119 of file NSMVar.h.

119{ return m_name; }

◆ getNode()

const std::string & getNode ( ) const
inline

Definition at line 118 of file NSMVar.h.

118{ return m_node; }

◆ getText()

const char * getText ( ) const

Definition at line 206 of file NSMVar.cc.

207{
208 return (m_type == TEXT && m_len > 0 && m_value != NULL) ? (const char*)m_value : "";
209}

◆ getType()

Type getType ( ) const
inline

Definition at line 120 of file NSMVar.h.

120{ return m_type; }

◆ getTypeLabel()

const char * getTypeLabel ( ) const

Definition at line 85 of file NSMVar.cc.

86{
87 switch (m_type) {
88 case INT:
89 if (m_len > 0) return "inta";
90 else return "int";
91 case FLOAT:
92 if (m_len > 0) return "floata";
93 else return "float";
94 case TEXT: return "text";
95 default: break;
96 }
97 return "";
98}

◆ operator=() [1/6]

const NSMVar & operator= ( const NSMVar var)
inline

Definition at line 78 of file NSMVar.h.

79 {
80 copy(var.m_name, var.m_type, var.m_len, var.m_value, var.m_id, var.m_date);
81 m_node = var.m_node;
82 m_date = var.m_date;
83 return *this;
84 }

◆ operator=() [2/6]

const NSMVar & operator= ( const std::string &  val)
inline

Definition at line 95 of file NSMVar.h.

96 {
97 if (val.size() > 0) {
98 copy(m_name, TEXT, val.size(), val.c_str(), m_id);
99 } else {
100 copy(m_name, TEXT, 1, "", m_id);
101 }
102 return *this;
103 }

◆ operator=() [3/6]

const NSMVar & operator= ( const std::vector< float > &  val)

Definition at line 59 of file NSMVar.cc.

60{
61 if (m_value) free(m_value);
62 float* v = (float*)malloc(val.size() * sizeof(float));
63 for (size_t i = 0; i < val.size(); i++)
64 v[i] = val[i];
65 m_value = v;
66 m_type = FLOAT;
67 m_len = val.size();
68 m_date = Date().get();
69 return *this;
70}

◆ operator=() [4/6]

const NSMVar & operator= ( const std::vector< int > &  val)

Definition at line 46 of file NSMVar.cc.

47{
48 if (m_value) free(m_value);
49 int* v = (int*)malloc(val.size() * sizeof(int));
50 for (size_t i = 0; i < val.size(); i++)
51 v[i] = val[i];
52 m_value = v;
53 m_type = INT;
54 m_len = val.size();
55 m_date = Date().get();
56 return *this;
57}

◆ operator=() [5/6]

const NSMVar & operator= ( float  val)
inline

Definition at line 90 of file NSMVar.h.

91 {
92 copy(m_name, FLOAT, 0, &val, m_id);
93 return *this;
94 }

◆ operator=() [6/6]

const NSMVar & operator= ( int  val)
inline

Definition at line 85 of file NSMVar.h.

86 {
87 copy(m_name, INT, 0, &val, m_id);
88 return *this;
89 }

◆ operator>>() [1/5]

const NSMVar & operator>> ( float &  val) const
inline

Definition at line 107 of file NSMVar.h.

107{ val = getFloat(); return *this; }

◆ operator>>() [2/5]

const NSMVar & operator>> ( int &  val) const
inline

Definition at line 106 of file NSMVar.h.

106{ val = getInt(); return *this; }

◆ operator>>() [3/5]

const NSMVar & operator>> ( std::string &  val) const
inline

Definition at line 108 of file NSMVar.h.

108{ val = getText(); return *this; }

◆ operator>>() [4/5]

const NSMVar & operator>> ( std::vector< float > &  val) const

Definition at line 231 of file NSMVar.cc.

232{
233 float* pv = (float*)get();
234 val = std::vector<float>();
235 for (int i = 0; i < getLength(); i++) {
236 val.push_back(pv[i]);
237 }
238 return *this;
239}

◆ operator>>() [5/5]

const NSMVar & operator>> ( std::vector< int > &  val) const

Definition at line 221 of file NSMVar.cc.

222{
223 int* pv = (int*)get();
224 val = std::vector<int>();
225 for (int i = 0; i < getLength(); i++) {
226 val.push_back(pv[i]);
227 }
228 return *this;
229}

◆ readObject()

void readObject ( Reader reader)
overridevirtual

Implements Serializable.

Definition at line 127 of file NSMVar.cc.

128{
129 m_node = reader.readString();
130 m_name = reader.readString();
131 m_type = (Type)reader.readInt();
132 m_len = reader.readInt();
133 m_id = reader.readInt();
134 m_date = reader.readInt();
135 int len = (m_len > 0) ? m_len : 1;
136 int s = size();
137 if (s > 0) {
138 if (m_value) free(m_value);
139 m_value = malloc(s);
140 memset(m_value, 0, s);
141 switch (m_type) {
142 case INT: {
143 int* v = (int*)m_value;
144 for (int i = 0; i < len; i++) {
145 v[i] = reader.readInt();
146 }
147 } break;
148 case FLOAT: {
149 float* v = (float*)m_value;
150 for (int i = 0; i < len; i++) {
151 v[i] = reader.readFloat();
152 }
153 } break;
154 case TEXT: {
155 char* v = (char*)m_value;
156 // Use m_len condition instead of len due to empty string problem
157 for (int i = 0; i < m_len; i++) {
158 v[i] = reader.readChar();
159 }
160 } break;
161 default: return;
162 }
163 }
164}

◆ setDate() [1/2]

void setDate ( const Date date)
inline

Definition at line 131 of file NSMVar.h.

131{ m_date = date.get(); }

◆ setDate() [2/2]

void setDate ( int  date)
inline

Definition at line 130 of file NSMVar.h.

130{ m_date = date; }

◆ setId()

void setId ( int  id)
inline

Definition at line 129 of file NSMVar.h.

129{ m_id = id; }

◆ setName()

void setName ( const std::string &  name)
inline

Definition at line 114 of file NSMVar.h.

114{ m_name = name; }

◆ setNode()

void setNode ( const std::string &  node)
inline

Definition at line 113 of file NSMVar.h.

113{ m_node = node; }

◆ size()

int size ( ) const

Definition at line 72 of file NSMVar.cc.

73{
74 int s = 1;
75 switch (m_type) {
76 case NONE: return 0;
77 case INT: s = 4; break;
78 case FLOAT: s = 4; break;
79 case TEXT: return m_len + 1;
80 default: break;
81 }
82 return (m_len > 0) ? s * m_len : s;
83}

◆ writeObject()

void writeObject ( Writer writer) const
overridevirtual

Implements Serializable.

Definition at line 166 of file NSMVar.cc.

167{
168 writer.writeString(m_node);
169 writer.writeString(m_name);
170 writer.writeInt((int)m_type);
171 writer.writeInt(m_len);
172 writer.writeInt(m_id);
173 writer.writeInt(m_date);
174 int len = (m_len > 0) ? m_len : 1;
175 switch (m_type) {
176 case INT: {
177 int* v = (int*)m_value;
178 for (int i = 0; i < len; i++) {
179 writer.writeInt(v[i]);
180 }
181 } break;
182 case FLOAT: {
183 float* v = (float*)m_value;
184 for (int i = 0; i < len; i++) {
185 writer.writeFloat(v[i]);
186 }
187 } break;
188 case TEXT: {
189 char* v = (char*)m_value;
190 writer.write(v, len);
191 } break;
192 default: return;
193 }
194}

Member Data Documentation

◆ m_date

int m_date
private

Definition at line 149 of file NSMVar.h.

◆ m_id

int m_id
private

Definition at line 148 of file NSMVar.h.

◆ m_len

int m_len
private

Definition at line 147 of file NSMVar.h.

◆ m_name

std::string m_name
private

Definition at line 145 of file NSMVar.h.

◆ m_node

std::string m_node
private

Definition at line 144 of file NSMVar.h.

◆ m_type

Type m_type
private

Definition at line 146 of file NSMVar.h.

◆ m_value

void* m_value
private

Definition at line 143 of file NSMVar.h.

◆ NOVALUE

const NSMVar NOVALUE
static

Definition at line 34 of file NSMVar.h.


The documentation for this class was generated from the following files: