1 #ifndef _Belle2_NSMVar_h
2 #define _Belle2_NSMVar_h
4 #include <daq/slc/base/Serializable.h>
5 #include <daq/slc/base/Date.h>
27 static const NSMVar NOVALUE;
30 NSMVar() : m_value(NULL), m_name(), m_type(NONE), m_len(0)
34 NSMVar(
const std::string& name, Type type,
int len,
const void* value)
37 copy(name, type, len, value);
39 NSMVar(
const std::string& name,
const std::string& value)
42 copy(name, TEXT, value.size(), value.c_str());
44 NSMVar(
const std::string& name,
int value)
47 copy(name, INT, 0, &value);
49 NSMVar(
const std::string& name,
float value)
52 copy(name, FLOAT, 0, &value);
54 NSMVar(
const std::string& name,
int len,
int* value)
57 copy(name, INT, len, value);
59 NSMVar(
const std::string& name,
int len,
float* value)
62 copy(name, FLOAT, len, value);
64 NSMVar(
const std::string& name,
const std::vector<int>& value);
65 NSMVar(
const std::string& name,
const std::vector<float>& value);
66 NSMVar(
const std::string& name) : m_value(NULL), m_name(name), m_type(NONE), m_len(0) {}
67 NSMVar(
const NSMVar& var) : m_value(NULL) { *
this = var; }
73 copy(var.m_name, var.m_type, var.m_len, var.m_value, var.m_id, var.m_date);
78 const NSMVar& operator=(
int val)
80 copy(m_name, INT, 0, &val, m_id);
83 const NSMVar& operator=(
float val)
85 copy(m_name, FLOAT, 0, &val, m_id);
88 const NSMVar& operator=(
const std::string& val)
91 copy(m_name, TEXT, val.size(), val.c_str(), m_id);
93 copy(m_name, TEXT, 1,
"", m_id);
97 const NSMVar& operator=(
const std::vector<int>& val);
98 const NSMVar& operator=(
const std::vector<float>& val);
99 const NSMVar& operator>>(
int& val)
const { val = getInt();
return *
this; }
100 const NSMVar& operator>>(
float& val)
const { val = getFloat();
return *
this; }
101 const NSMVar& operator>>(std::string& val)
const { val = getText();
return *
this; }
102 const NSMVar& operator>>(std::vector<int>& val)
const;
106 void setNode(
const std::string& node) { m_node = node; }
107 void setName(
const std::string& name) { m_name = name; }
108 const void* get()
const {
return m_value; }
109 void* get() {
return m_value; }
111 const std::string& getNode()
const {
return m_node; }
112 const std::string& getName()
const {
return m_name; }
113 Type getType()
const {
return m_type; }
114 const char* getTypeLabel()
const;
115 int getLength()
const {
return m_len; }
117 float getFloat()
const;
118 const char* getText()
const;
119 int getInt(
int i)
const;
120 float getFloat(
int i)
const;
121 int getId()
const {
return m_id; }
122 void setId(
int id) { m_id = id; }
123 void setDate(
int date) { m_date = date; }
124 void setDate(
const Date& date) { m_date = date.get(); }
125 int getDate()
const {
return m_date; }
128 virtual void readObject(
Reader&);
129 virtual void writeObject(
Writer&)
const;
132 void copy(
const std::string& name, Type type,
int len,
133 const void* value,
int id = 0,
int date = 0);
146 typedef std::vector<NSMVar> NSMVarList;