49#ifndef DOXYGEN_SHOULD_SKIP_THIS
59 GUM_CONSTRUCTOR(DBCell);
64 INLINE DBCell::DBCell(
const float nb) : _type_(DBCell::EltType::REAL), _val_real_(nb) {
65 GUM_CONSTRUCTOR(DBCell);
69 INLINE DBCell::DBCell(
const int nb) : _type_(DBCell::EltType::
INTEGER), _val_integer_(nb) {
70 GUM_CONSTRUCTOR(DBCell);
74 INLINE DBCell::DBCell(
const std::string& str) : _type_(DBCell::EltType::STRING) {
76 if (!_strings_().existsFirst(str)) {
77 _strings_().insert(str, _string_max_index_);
78 _val_index_ = _string_max_index_;
81 _val_index_ = _strings_().second(str);
84 GUM_CONSTRUCTOR(DBCell);
88 INLINE DBCell::DBCell(
const DBCell& from) : _type_(from._type_) {
89 std::memcpy(&_val_index_, &(from._val_index_),
sizeof(UnionType));
96 INLINE DBCell::DBCell(DBCell&& from) : _type_(from._type_) {
97 std::memcpy(&_val_index_, &(from._val_index_),
sizeof(UnionType));
100 GUM_CONS_MOV(DBCell);
104 INLINE DBCell::~DBCell() {
105 GUM_DESTRUCTOR(DBCell);
110 INLINE DBCell& DBCell::operator=(
const DBCell& from) {
112 _type_ = from._type_;
113 std::memcpy(&_val_index_, &(from._val_index_),
sizeof(UnionType));
120 INLINE DBCell& DBCell::operator=(DBCell&& from) {
122 _type_ = from._type_;
123 std::memcpy(&_val_index_, &(from._val_index_),
sizeof(UnionType));
130 INLINE DBCell& DBCell::operator=(
const float x) {
131 _type_ = EltType::REAL;
137 INLINE DBCell& DBCell::operator=(
const int x) {
138 _type_ = EltType::INTEGER;
144 INLINE DBCell& DBCell::operator=(
const std::string& str) {
145 if (!_strings_().existsFirst(str)) {
146 _strings_().insert(str, _string_max_index_);
147 _val_index_ = _string_max_index_;
148 ++_string_max_index_;
150 _val_index_ = _strings_().second(str);
152 _type_ = EltType::STRING;
158 INLINE
bool DBCell::operator==(
const DBCell& from)
const {
159 return (_type_ == from._type_)
160 && ((_type_ == EltType::MISSING)
161 || ((_type_ == EltType::REAL) && (_val_real_ == from._val_real_))
162 || (_val_integer_ == from._val_integer_));
166 INLINE
bool DBCell::operator!=(
const DBCell& from)
const {
return !
operator==(from); }
169 INLINE DBCell::EltType DBCell::type() const noexcept {
return _type_; }
172 INLINE
float DBCell::real()
const {
173 if (_type_ == EltType::REAL)
return _val_real_;
178 INLINE
void DBCell::setReal(
const float x) {
179 _type_ = EltType::REAL;
184 INLINE
void DBCell::setReal(
const std::string& elt) {
186 _val_real_ =
std::stof(elt);
187 _type_ = EltType::REAL;
191 INLINE
int DBCell::integer()
const {
192 if (_type_ == EltType::INTEGER)
return _val_integer_;
197 INLINE
void DBCell::setInteger(
const int x) {
198 _type_ = EltType::INTEGER;
203 INLINE
void DBCell::setInteger(
const std::string& elt) {
205 _val_integer_ =
std::stoi(elt);
206 _type_ = EltType::INTEGER;
210 INLINE const
std::
string& DBCell::
string()
const {
211 if (_type_ == EltType::STRING)
return _strings_().first(_val_index_);
216 INLINE
int DBCell::stringIndex()
const {
217 if (_type_ == EltType::STRING)
return _val_index_;
222 INLINE
const std::string& DBCell::string(
const int index) {
return _strings_().first(index); }
225 INLINE
void DBCell::setString(
const std::string& str) {
226 if (!_strings_().existsFirst(str)) {
227 _strings_().insert(str, _string_max_index_);
228 _val_index_ = _string_max_index_;
229 ++_string_max_index_;
231 _val_index_ = _strings_().second(str);
233 _type_ = EltType::STRING;
237 INLINE
void DBCell::setMissingState() { _type_ = EltType::MISSING; }
240 INLINE
bool DBCell::isMissing()
const {
return _type_ == EltType::MISSING; }
243 INLINE
bool DBCell::isMissing(
const std::string& str,
244 const std::vector< std::string >& missingVals) {
245 for (
auto missing: missingVals) {
246 if (str == missing)
return true;
252 INLINE DBCell::EltType DBCell::bestType(
const std::string& str,
253 const std::vector< std::string >& missingVals) {
254 if (isMissing(str, missingVals))
return EltType::MISSING;
255 if (
isInteger(str))
return EltType::INTEGER;
256 if (isReal(str))
return EltType::REAL;
257 return EltType::STRING;
261 INLINE DBCell DBCell::bestDBCell(
const std::string& str,
262 const std::vector< std::string >& missingVals) {
263 if (isMissing(str, missingVals))
return DBCell();
264 if (
isInteger(str))
return DBCell(std::stoi(str));
265 if (isReal(str))
return DBCell(std::stof(str));
The class representing the original values of the cells of databases.
Exception : wrong type for this operation.
DBCell()
default constructor (ontains a missing value)
#define GUM_ERROR(type, msg)
bool isInteger(const std::string &val)
return true is a string contains an integer value
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities
bool operator==(const TiXmlString &a, const TiXmlString &b)