#include <Datatype.h>
Definition at line 28 of file Datatype.h.
Definition at line 44 of file Datatype.h.
00044 { 00045 RESTRICTnone = 0, 00046 RESTRICTnonneg, // value must be non-negative 00047 RESTRICTpos, // value must be strictly positive 00048 RESTRICTinterval, // value (numeric or datetime) must be in interval 00049 RESTRICTenum, // restrict to, or suggest, enumerated set 00050 RESTRICTfile // value must have valid file path syntax 00051 };
TYPEnotFound | |
TYPEenum | |
TYPEdatetime | |
TYPEtimestamp | |
TYPEint | |
TYPEmediumint | |
TYPEsmallint | |
TYPEreal | |
TYPEdouble | |
TYPEvarchar | |
TYPEchar |
Definition at line 31 of file Datatype.h.
00031 { 00032 TYPEnotFound = -1, 00033 TYPEenum = 0, 00034 TYPEdatetime, 00035 TYPEtimestamp, 00036 TYPEint, 00037 TYPEmediumint, 00038 TYPEsmallint, 00039 TYPEreal, 00040 TYPEdouble, 00041 TYPEvarchar, 00042 TYPEchar 00043 };
rdbModel::Datatype::Datatype | ( | ) | [inline] |
Definition at line 53 of file Datatype.h.
00053 : m_restrict(RESTRICTnone), m_enum(0), m_isInt(false) {}
rdbModel::Datatype::~Datatype | ( | ) | [inline] |
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.
References m_enum.
Referenced by rdbModel::MysqlConnection::checkDType(), and rdbModel::Column::getEnum().
00064 {return m_enum;}
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. true if there is a min & max, false otherwise
Definition at line 154 of file Datatype.cxx.
References m_max, m_min, m_restrict, and RESTRICTinterval.
Referenced by main().
00154 { 00155 if (m_restrict == RESTRICTinterval) { 00156 min = m_min; 00157 max = m_max; 00158 return true; 00159 } 00160 return false; 00161 }
int rdbModel::Datatype::getOutputSize | ( | ) | const [inline] |
Definition at line 60 of file Datatype.h.
References m_outputSize.
Referenced by rdbModel::MysqlConnection::checkDType().
00060 {return m_outputSize;}
RESTRICT rdbModel::Datatype::getRestrict | ( | ) | const [inline] |
TYPES rdbModel::Datatype::getType | ( | ) | const [inline] |
Definition at line 59 of file Datatype.h.
References m_type.
Referenced by rdbModel::MysqlConnection::checkDType(), rdbModel::Column::interpret(), and rdbModel::Assertion::Operator::verifyCompare().
00059 {return m_type;}
Definition at line 237 of file Datatype.cxx.
References findTOT(), m_type, and EvtCyclic3::other().
Referenced by rdbModel::Column::isCompatible().
00237 { 00238 // The ten distinct types can be partitioned into 4 sorts: integer, 00239 // real, character, and date. Call two types compatible if they're 00240 // in the same partition. 00241 return (findTOT(m_type) == findTOT(other->m_type)); 00242 }
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.
References rdbModel::Enum::choicesRequired(), facilities::BadTimeInput::complaint, rdbModel::Enum::getChoices(), genRecEmupikp::i, m_enum, m_max, m_maxInt, m_min, m_minInt, m_restrict, m_type, max, min, RESTRICTfile, RESTRICTinterval, RESTRICTnone, RESTRICTnonneg, RESTRICTpos, TYPEchar, TYPEdatetime, TYPEdouble, TYPEenum, TYPEint, TYPEmediumint, TYPEreal, TYPEsmallint, TYPEtimestamp, and TYPEvarchar.
Referenced by rdbModel::Column::okValue().
00164 { 00165 using facilities::Util; 00166 00167 switch (m_type) { 00168 case TYPEreal: 00169 case TYPEdouble: { 00170 double doubleVal; 00171 try { 00172 doubleVal = Util::stringToDouble(val); 00173 } 00174 catch (facilities::WrongType ex) { 00175 return false; 00176 } 00177 if (m_restrict == RESTRICTnonneg) return (doubleVal >= 0.0 ); 00178 else if (m_restrict == RESTRICTpos) return (doubleVal > 0.0); 00179 else if (m_restrict == RESTRICTinterval) { 00180 double min = Util::stringToDouble(m_min); 00181 double max = Util::stringToDouble(m_max); 00182 return ((min <= doubleVal) && (doubleVal <= max)); 00183 } 00184 return true; 00185 00186 } 00187 00188 case TYPEint: 00189 case TYPEmediumint: 00190 case TYPEsmallint: { 00191 int intVal; 00192 00193 try { 00194 intVal = Util::stringToInt(val); 00195 } 00196 catch (facilities::WrongType ex) { 00197 return false; 00198 } 00199 return ((intVal >= m_minInt) && (intVal <= m_maxInt)); 00200 } 00201 case TYPEvarchar: 00202 case TYPEchar: 00203 if (m_restrict == RESTRICTnone) return true; 00204 // for now, don't attempt to parse file path 00205 if (m_restrict == RESTRICTfile) return true; 00206 if (!m_enum->choicesRequired()) return true; 00207 case TYPEenum: { 00208 unsigned nChoice = m_enum->getChoices().size(); 00209 for (unsigned i = 0; i < nChoice; i++) { 00210 if (val == m_enum->getChoices()[i]) return true; 00211 } 00212 return false; 00213 } 00214 case TYPEdatetime: 00215 case TYPEtimestamp: { 00216 try { 00217 facilities::Timestamp aTime(val); 00218 if (m_restrict == RESTRICTinterval) { 00219 facilities::Timestamp min(m_min); 00220 facilities::Timestamp max(m_max); 00221 return ((min <= aTime) && (aTime <= max)); 00222 } 00223 return true; 00224 } 00225 catch (facilities::BadTimeInput ex) { 00226 std::cerr << "From rdbModel::Datatype::okValue" << std::endl; 00227 std::cerr << ex.complaint << std::endl; 00228 return false; 00229 } 00230 00231 } 00232 default: 00233 return false; 00234 } 00235 }
bool rdbModel::Datatype::setInterval | ( | const std::string & | min, | |
const std::string & | max | |||
) | [private] |
Definition at line 92 of file Datatype.cxx.
References facilities::BadTimeInput::complaint, m_isInt, m_max, m_maxInt, m_min, m_minInt, m_restrict, m_type, RESTRICTinterval, TYPEchar, TYPEdatetime, TYPEdouble, TYPEenum, typenames, TYPEreal, and TYPEvarchar.
00092 { 00093 bool ret = false; 00094 // if ((m_type == TYPEtimestamp) || (m_type == TYPEenum) || 00095 if ( (m_type == TYPEenum) || 00096 (m_type == TYPEchar) || (m_type == TYPEvarchar)) { 00097 std::cerr << "From rdbModel::Datatype::setInterval " << std::endl; 00098 std::cerr << "Cannot set interval restriction for type " << 00099 typenames[m_type] << std::endl; 00100 return false; 00101 } 00102 00103 m_restrict = RESTRICTinterval; 00104 m_min = min; 00105 m_max = max; 00106 00107 // In case data is some integer type, convert min and max to integers, 00108 // store. Return false if anything about them is unreasonable. 00109 if (m_isInt) { 00110 try { 00111 int minInt = facilities::Util::stringToInt(min); 00112 int maxInt = facilities::Util::stringToInt(max); 00113 if (minInt > m_minInt) m_minInt = minInt; 00114 if (maxInt < m_maxInt) m_maxInt = maxInt; 00115 } 00116 catch (facilities::WrongType ex) { 00117 std::cerr << "Error detected in XercesBuilder::buildDatatype " 00118 << std::endl; 00119 std::cerr << ex.getMsg() << std::endl; 00120 return false; 00121 } 00122 ret = (m_min < m_max); 00123 } 00124 // Don't expect to encounter interval restriction for floating point, 00125 // so don't bother to cache values, but at least check for validity 00126 if ((m_type == TYPEdouble) || (m_type == TYPEreal)) { 00127 try { 00128 double minFloat = facilities::Util::stringToDouble(min); 00129 double maxFloat = facilities::Util::stringToDouble(max); 00130 ret = (minFloat < maxFloat); 00131 } 00132 catch (facilities::WrongType ex) { 00133 std::cerr << "Error detected in XercesBuilder::buildDatatype " 00134 << std::endl; 00135 std::cerr << ex.getMsg() << std::endl; 00136 return false; 00137 } 00138 } 00139 if (m_type == TYPEdatetime) { 00140 try { 00141 facilities::Timestamp minTime(min); 00142 facilities::Timestamp maxTime(max); 00143 ret = (minTime < maxTime); 00144 } 00145 catch (facilities::BadTimeInput ex) { 00146 std::cerr << "From rdbModel::Datatype::setInterval" << std::endl; 00147 std::cerr << ex.complaint << std::endl; 00148 return false; 00149 } 00150 } 00151 return ret; 00152 }
int rdbModel::Datatype::setType | ( | std::string | name | ) | [private] |
Definition at line 57 of file Datatype.cxx.
References findType(), m_isInt, m_maxInt, m_minInt, m_type, m_typename, TYPEint, TYPEmediumint, and TYPEsmallint.
00057 { 00058 m_type = (TYPES) findType(name); 00059 if (m_type >=0 ) { 00060 m_typename = name; 00061 } 00062 00063 // Set up initial restrictions for integer-like types. These 00064 // values come from the MySQL doc. See e.g. 00065 // http://www.mysql.com/documentation/mysql/bychapter/manual_Column_types.html#Numeric_types 00066 switch (m_type) { 00067 case TYPEint: { 00068 m_maxInt = 2147483647; 00069 m_minInt = -2147483647; 00070 m_isInt = true; 00071 break; 00072 } 00073 case TYPEmediumint: { 00074 m_maxInt = 8388607; 00075 m_minInt = -8388608; 00076 m_isInt = true; 00077 break; 00078 } 00079 case TYPEsmallint: { 00080 m_maxInt = 32767; 00081 m_minInt = -32768; 00082 m_isInt = true; 00083 break; 00084 } 00085 default: 00086 break; 00087 } 00088 return m_type; 00089 }
friend class rdbModel::XercesBuilder [friend] |
Definition at line 75 of file Datatype.h.
Enum* rdbModel::Datatype::m_enum [private] |
bool rdbModel::Datatype::m_isInt [private] |
std::string rdbModel::Datatype::m_max [private] |
Definition at line 96 of file Datatype.h.
Referenced by getInterval(), okValue(), and setInterval().
int rdbModel::Datatype::m_maxInt [private] |
std::string rdbModel::Datatype::m_min [private] |
Definition at line 95 of file Datatype.h.
Referenced by getInterval(), okValue(), and setInterval().
int rdbModel::Datatype::m_minInt [private] |
int rdbModel::Datatype::m_outputSize [private] |
RESTRICT rdbModel::Datatype::m_restrict [private] |
Definition at line 91 of file Datatype.h.
Referenced by getInterval(), getRestrict(), okValue(), and setInterval().
TYPES rdbModel::Datatype::m_type [private] |
Definition at line 90 of file Datatype.h.
Referenced by getType(), isCompatible(), okValue(), setInterval(), and setType().
std::string rdbModel::Datatype::m_typename [private] |