BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
rdbModel::Datatype Class Reference

#include <Datatype.h>

Public Types

enum  TYPES {
  TYPEnotFound = -1 , TYPEenum = 0 , TYPEdatetime , TYPEtimestamp ,
  TYPEint , TYPEmediumint , TYPEsmallint , TYPEreal ,
  TYPEdouble , TYPEvarchar , TYPEchar
}
 
enum  RESTRICT {
  RESTRICTnone = 0 , RESTRICTnonneg , RESTRICTpos , RESTRICTinterval ,
  RESTRICTenum , RESTRICTfile
}
 

Public Member Functions

 Datatype ()
 
 ~Datatype ()
 
bool okValue (const std::string &val) const
 
bool isCompatible (const Datatype *other) const
 
TYPES getType () const
 
int getOutputSize () const
 
EnumgetEnum () const
 
RESTRICT getRestrict () const
 
bool getInterval (std::string &min, std::string &max)
 

Friends

class rdbModel::XercesBuilder
 

Detailed Description

Definition at line 28 of file Datatype.h.

Member Enumeration Documentation

◆ RESTRICT

Enumerator
RESTRICTnone 
RESTRICTnonneg 
RESTRICTpos 
RESTRICTinterval 
RESTRICTenum 
RESTRICTfile 

Definition at line 44 of file Datatype.h.

44 {
45 RESTRICTnone = 0,
46 RESTRICTnonneg, // value must be non-negative
47 RESTRICTpos, // value must be strictly positive
48 RESTRICTinterval, // value (numeric or datetime) must be in interval
49 RESTRICTenum, // restrict to, or suggest, enumerated set
50 RESTRICTfile // value must have valid file path syntax
51 };

◆ TYPES

Enumerator
TYPEnotFound 
TYPEenum 
TYPEdatetime 
TYPEtimestamp 
TYPEint 
TYPEmediumint 
TYPEsmallint 
TYPEreal 
TYPEdouble 
TYPEvarchar 
TYPEchar 

Definition at line 31 of file Datatype.h.

Constructor & Destructor Documentation

◆ Datatype()

rdbModel::Datatype::Datatype ( )
inline

Definition at line 53 of file Datatype.h.

53: m_restrict(RESTRICTnone), m_enum(0), m_isInt(false) {}

◆ ~Datatype()

rdbModel::Datatype::~Datatype ( )
inline

Definition at line 54 of file Datatype.h.

54{if (m_enum) delete m_enum;}

Member Function Documentation

◆ getEnum()

Enum * rdbModel::Datatype::getEnum ( ) const
inline

Return pointer to Enum object owned by datatype (if none, return null pointer).

Definition at line 64 of file Datatype.h.

64{return m_enum;}

Referenced by rdbModel::Column::getEnum().

◆ getInterval()

bool rdbModel::Datatype::getInterval ( std::string &  min,
std::string &  max 
)

User-supplied strings min and max will be set to min and max values, if any, for the Datatype object.
@ret true if there is a min & max, false otherwise

Definition at line 154 of file Datatype.cxx.

154 {
155 if (m_restrict == RESTRICTinterval) {
156 min = m_min;
157 max = m_max;
158 return true;
159 }
160 return false;
161 }

Referenced by main().

◆ getOutputSize()

int rdbModel::Datatype::getOutputSize ( ) const
inline

Definition at line 60 of file Datatype.h.

60{return m_outputSize;}

◆ getRestrict()

RESTRICT rdbModel::Datatype::getRestrict ( ) const
inline

Definition at line 65 of file Datatype.h.

65{return m_restrict;}

◆ getType()

TYPES rdbModel::Datatype::getType ( ) const
inline

Definition at line 59 of file Datatype.h.

59{return m_type;}

Referenced by rdbModel::Column::interpret().

◆ isCompatible()

bool rdbModel::Datatype::isCompatible ( const Datatype other) const

Definition at line 237 of file Datatype.cxx.

237 {
238 // The ten distinct types can be partitioned into 4 sorts: integer,
239 // real, character, and date. Call two types compatible if they're
240 // in the same partition.
241 return (findTOT(m_type) == findTOT(other->m_type));
242 }
Index other(Index i, Index j)
Definition: EvtCyclic3.cc:118

Referenced by rdbModel::Column::isCompatible().

◆ okValue()

bool rdbModel::Datatype::okValue ( const std::string &  val) const

Check that supplied string has proper syntax for our type and is in accord with restriction, if any

Definition at line 164 of file Datatype.cxx.

164 {
165 using facilities::Util;
166
167 switch (m_type) {
168 case TYPEreal:
169 case TYPEdouble: {
170 double doubleVal;
171 try {
172 doubleVal = Util::stringToDouble(val);
173 }
174 catch (facilities::WrongType ex) {
175 return false;
176 }
177 if (m_restrict == RESTRICTnonneg) return (doubleVal >= 0.0 );
178 else if (m_restrict == RESTRICTpos) return (doubleVal > 0.0);
179 else if (m_restrict == RESTRICTinterval) {
180 double min = Util::stringToDouble(m_min);
181 double max = Util::stringToDouble(m_max);
182 return ((min <= doubleVal) && (doubleVal <= max));
183 }
184 return true;
185
186 }
187
188 case TYPEint:
189 case TYPEmediumint:
190 case TYPEsmallint: {
191 int intVal;
192
193 try {
194 intVal = Util::stringToInt(val);
195 }
196 catch (facilities::WrongType ex) {
197 return false;
198 }
199 return ((intVal >= m_minInt) && (intVal <= m_maxInt));
200 }
201 case TYPEvarchar:
202 case TYPEchar:
203 if (m_restrict == RESTRICTnone) return true;
204 // for now, don't attempt to parse file path
205 if (m_restrict == RESTRICTfile) return true;
206 if (!m_enum->choicesRequired()) return true;
207 case TYPEenum: {
208 unsigned nChoice = m_enum->getChoices().size();
209 for (unsigned i = 0; i < nChoice; i++) {
210 if (val == m_enum->getChoices()[i]) return true;
211 }
212 return false;
213 }
214 case TYPEdatetime:
215 case TYPEtimestamp: {
216 try {
217 facilities::Timestamp aTime(val);
218 if (m_restrict == RESTRICTinterval) {
221 return ((min <= aTime) && (aTime <= max));
222 }
223 return true;
224 }
225 catch (facilities::BadTimeInput ex) {
226 std::cerr << "From rdbModel::Datatype::okValue" << std::endl;
227 std::cerr << ex.complaint << std::endl;
228 return false;
229 }
230
231 }
232 default:
233 return false;
234 }
235 }
std::string complaint
Definition: Timestamp.h:17
Exception class used when converting from string to numeric type.
const std::vector< std::string > & getChoices() const
Definition: Datatype.h:16
bool choicesRequired() const
Definition: Datatype.h:18

Referenced by rdbModel::Column::okValue().

Friends And Related Function Documentation

◆ rdbModel::XercesBuilder

friend class rdbModel::XercesBuilder
friend

Definition at line 75 of file Datatype.h.


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