Belle II Software development
AbstractDBObject Class Referenceabstract
Inheritance diagram for AbstractDBObject:
Serializable DBObject NSMData

Public Member Functions

 AbstractDBObject (const AbstractDBObject &obj)
 
const AbstractDBObjectoperator= (const AbstractDBObject &object)
 Operator =.
 
const std::string & getPath () const
 
void setPath (const std::string &path)
 
int getId () const
 
void setId (int id)
 
const std::string & getName () const
 
void setName (const std::string &name)
 
int getIndex () const
 
void setIndex (int index)
 
DBField::NameList & getFieldNames ()
 
const DBField::NameList & getFieldNames () const
 
DBField::Property getProperty (const std::string &name) const
 
bool hasField (const std::string &name) const
 
bool hasValue (const std::string &name) const
 
bool hasText (const std::string &name) const
 
bool hasObject (const std::string &name) const
 
void add (const std::string &name, DBField::Property pro)
 
void setValue (const std::string &name, const std::string &value)
 
void setText (const std::string &name, const std::string &value)
 
bool getBool (const std::string &name, int index=0) const
 
char getChar (const std::string &name, int index=0) const
 
short getShort (const std::string &name, int index=0) const
 
int getInt (const std::string &name, int index=0) const
 
long long getLong (const std::string &name, int index=0) const
 
float getFloat (const std::string &name, int index=0) const
 
double getDouble (const std::string &name, int index=0) const
 
void addBool (const std::string &name, bool value)
 
void addChar (const std::string &name, char value)
 
void addShort (const std::string &name, short value)
 
void addInt (const std::string &name, int value)
 
void addLong (const std::string &name, long long value)
 
void addFloat (const std::string &name, float value)
 
void addDouble (const std::string &name, double value)
 
void setBool (const std::string &name, bool value, int index=0)
 
void setChar (const std::string &name, int value, int index=0)
 
void setShort (const std::string &name, int value, int index=0)
 
void setInt (const std::string &name, int value, int index=0)
 
void setLong (const std::string &name, long long value, int index=0)
 
void setFloat (const std::string &name, float value, int index=0)
 
void setDouble (const std::string &name, double value, int index=0)
 
const std::string getValueText (const std::string &name) const
 
virtual const void * getValue (const std::string &name) const =0
 
virtual const std::string & getText (const std::string &name) const =0
 
virtual void addText (const std::string &name, const std::string &value)=0
 
virtual void addValue (const std::string &name, const void *value, DBField::Type type, int length)=0
 
virtual void setValue (const std::string &name, const void *value, int index)=0
 
virtual void setValueText (const std::string &name, const std::string &value)
 
virtual void readObject (Reader &)=0
 
virtual void writeObject (Writer &) const =0
 

Protected Member Functions

virtual void reset ()
 

Private Member Functions

template<typename T >
getD (const std::string &name, int index=0) const
 

Private Attributes

int m_index
 
std::string m_path
 
int m_id
 
std::string m_name
 
DBField::NameList m_name_v
 
DBField::PropertyList m_pro_m
 

Detailed Description

Definition at line 25 of file AbstractDBObject.h.

Constructor & Destructor Documentation

◆ AbstractDBObject() [1/2]

Definition at line 17 of file AbstractDBObject.cc.

17 : m_index(0), m_path(), m_id(0)
18{
19
20}

◆ AbstractDBObject() [2/2]

Definition at line 22 of file AbstractDBObject.cc.

23 : m_index(obj.m_index), m_path(obj.m_path),
24 m_id(obj.m_id),
25 m_name(obj.m_name) {}

◆ ~AbstractDBObject()

~AbstractDBObject ( )
virtual

Definition at line 27 of file AbstractDBObject.cc.

28{
29 reset();
30}

Member Function Documentation

◆ add()

void add ( const std::string &  name,
DBField::Property  pro 
)

Definition at line 88 of file AbstractDBObject.cc.

89{
90 if (!hasField(name)) {
91 m_name_v.push_back(name);
92 m_pro_m.insert(DBField::PropertyList::value_type(name, pro));
93 }
94}

◆ getD()

T getD ( const std::string &  name,
int  index = 0 
) const
inlineprivate

Definition at line 103 of file AbstractDBObject.h.

104 {
105 const void* value = getValue(name);
106 if (value == NULL/* || index >= getProperty(name).getLength()*/) {
107 throw (std::out_of_range(name + " not found"));
108 }
109 DBField::Type type(getProperty(name).getType());
110 if (type == DBField::INT) return (T)(((int*)value)[index]);
111 if (type == DBField::FLOAT) return (T)(((float*)value)[index]);
112 if (type == DBField::DOUBLE) return (T)(((double*)value)[index]);
113 if (type == DBField::SHORT) return (T)(((short*)value)[index]);
114 if (type == DBField::CHAR) return (T)(((char*)value)[index]);
115 if (type == DBField::LONG) return (T)(((long*)value)[index]);
116 return ((T*)value)[index];
117 }

◆ getFieldNames() [1/2]

DBField::NameList & getFieldNames ( )
inline

Definition at line 46 of file AbstractDBObject.h.

46{ return m_name_v; }

◆ getFieldNames() [2/2]

const DBField::NameList & getFieldNames ( ) const
inline

Definition at line 47 of file AbstractDBObject.h.

47{ return m_name_v; }

◆ getId()

int getId ( ) const
inline

Definition at line 40 of file AbstractDBObject.h.

40{ return m_id; }

◆ getIndex()

int getIndex ( ) const
inline

Definition at line 44 of file AbstractDBObject.h.

44{ return m_index; }

◆ getName()

const std::string & getName ( ) const
inline

Definition at line 42 of file AbstractDBObject.h.

42{ return m_name; }

◆ getPath()

const std::string & getPath ( ) const
inline

Definition at line 38 of file AbstractDBObject.h.

38{ return m_path; }

◆ getProperty()

DBField::Property getProperty ( const std::string &  name) const

Definition at line 54 of file AbstractDBObject.cc.

55{
56 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
57 if (it != m_pro_m.end()) return it->second;
58 return DBField::Property();
59}

◆ getValueText()

const std::string getValueText ( const std::string &  name) const

Definition at line 96 of file AbstractDBObject.cc.

98{
99 const static int double_precision = std::numeric_limits<double>::digits10 + 2;
100
101 if (hasField(name)) {
102 switch (getProperty(name).getType()) {
103 case DBField::BOOL: return getBool(name) ? "true" : "false";
104 case DBField::CHAR: return StringUtil::form("%d", (int)getChar(name));
105 case DBField::SHORT: return StringUtil::form("%d", (int)getShort(name));
106 case DBField::INT: return StringUtil::form("%d", (int)getInt(name));
107 case DBField::LONG: return StringUtil::form("%ld", getLong(name));
108 case DBField::FLOAT: return StringUtil::form("%f", getFloat(name));
109 case DBField::DOUBLE: return StringUtil::form("%.*e", double_precision, getDouble(name));
110 case DBField::TEXT: return getText(name);
111 default: break;
112 }
113 }
114 throw (std::out_of_range(name + " not found"));
115}

◆ hasField()

bool hasField ( const std::string &  name) const

Definition at line 61 of file AbstractDBObject.cc.

62{
63 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
64 return (it != m_pro_m.end());
65}

◆ hasObject()

bool hasObject ( const std::string &  name) const

Definition at line 81 of file AbstractDBObject.cc.

82{
83 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
84 return hasField(name) &&
85 it->second.getType() == DBField::OBJECT;
86}

◆ hasText()

bool hasText ( const std::string &  name) const

Definition at line 75 of file AbstractDBObject.cc.

76{
77 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
78 return hasField(name) && it->second.getType() == DBField::TEXT;
79}

◆ hasValue()

bool hasValue ( const std::string &  name) const

Definition at line 67 of file AbstractDBObject.cc.

68{
69 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
70 return hasField(name) &&
71 it->second.getType() != DBField::TEXT &&
72 it->second.getType() != DBField::OBJECT;
73}

◆ operator=()

const AbstractDBObject & operator= ( const AbstractDBObject object)

Operator =.

Definition at line 32 of file AbstractDBObject.cc.

34{
35 Serializable::operator=(object);
36 m_index = object.m_index;
37 m_path = object.m_path;
38 m_id = object.m_id;
39 m_name = object.m_name;
40 m_name_v = object.m_name_v;
41 m_pro_m = object.m_pro_m;
42 return *this;
43}

◆ reset()

void reset ( )
protectedvirtual

Definition at line 45 of file AbstractDBObject.cc.

46{
47 m_path = "";
48 m_id = 0;
49 m_index = 0;
50 m_name_v = DBField::NameList();
51 m_pro_m = DBField::PropertyList();
52}

◆ setId()

void setId ( int  id)
inline

Definition at line 41 of file AbstractDBObject.h.

41{ m_id = id; }

◆ setIndex()

void setIndex ( int  index)
inline

Definition at line 45 of file AbstractDBObject.h.

45{ m_index = index; }

◆ setName()

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

Definition at line 43 of file AbstractDBObject.h.

43{ m_name = name; }

◆ setPath()

void setPath ( const std::string &  path)
inline

Definition at line 39 of file AbstractDBObject.h.

39{ m_path = path; }

◆ setText()

void setText ( const std::string &  name,
const std::string &  value 
)
inline

Definition at line 55 of file AbstractDBObject.h.

55{ addText(name, value); }

◆ setValueText()

void setValueText ( const std::string &  name,
const std::string &  value 
)
virtual

Definition at line 117 of file AbstractDBObject.cc.

119{
120 if (hasField(name)) {
121 switch (getProperty(name).getType()) {
122 case DBField::BOOL: setBool(name, value == "true" || value == "t"); break;
123 case DBField::CHAR: {
124 if (StringUtil::find(value, "0x"))
125 setChar(name, (char)strtol(value.c_str(), NULL, 0));
126 else
127 setChar(name, (char)atoi(value.c_str()));
128 } break;
129 case DBField::SHORT: {
130 if (StringUtil::find(value, "0x"))
131 setShort(name, (short)strtol(value.c_str(), NULL, 0));
132 else
133 setShort(name, (short)atoi(value.c_str()));
134 } break;
135 case DBField::INT: {
136 if (StringUtil::find(value, "0x"))
137 setInt(name, (int)strtol(value.c_str(), NULL, 0));
138 else
139 setInt(name, (int)atoi(value.c_str()));
140 } break;
141 case DBField::LONG: setLong(name, (long long)atoi(value.c_str())); break;
142 case DBField::FLOAT: setFloat(name, atof(value.c_str())); break;
143 case DBField::DOUBLE: setDouble(name, atof(value.c_str())); break;
144 case DBField::TEXT: setText(name, value); break;
145 default: break;
146 }
147 return;
148 }
149 throw (std::out_of_range(name + " not found"));
150}

Member Data Documentation

◆ m_id

int m_id
private

Definition at line 96 of file AbstractDBObject.h.

◆ m_index

int m_index
private

Definition at line 94 of file AbstractDBObject.h.

◆ m_name

std::string m_name
private

Definition at line 97 of file AbstractDBObject.h.

◆ m_name_v

DBField::NameList m_name_v
private

Definition at line 98 of file AbstractDBObject.h.

◆ m_path

std::string m_path
private

Definition at line 95 of file AbstractDBObject.h.

◆ m_pro_m

DBField::PropertyList m_pro_m
private

Definition at line 99 of file AbstractDBObject.h.


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