51#ifndef DOXYGEN_SHOULD_SKIP_THIS
61 GUM_CONSTRUCTOR(DBCell);
66 INLINE DBCell::DBCell(
const float nb) : _type_(DBCell::EltType::REAL), _val_real_(nb) {
67 GUM_CONSTRUCTOR(DBCell);
71 INLINE DBCell::DBCell(
const int nb) : _type_(DBCell::EltType::
INTEGER), _val_integer_(nb) {
72 GUM_CONSTRUCTOR(DBCell);
76 INLINE DBCell::DBCell(
const std::string& str) : _type_(DBCell::EltType::STRING) {
78 if (!_strings_().existsFirst(str)) {
79 _strings_().insert(str, _string_max_index_);
80 _val_index_ = _string_max_index_;
83 _val_index_ = _strings_().second(str);
86 GUM_CONSTRUCTOR(DBCell);
90 INLINE DBCell::DBCell(
const DBCell& from) : _type_(from._type_) {
91 std::memcpy(&_val_index_, &(from._val_index_),
sizeof(UnionType));
98 INLINE DBCell::DBCell(DBCell&& from) : _type_(from._type_) {
99 std::memcpy(&_val_index_, &(from._val_index_),
sizeof(UnionType));
102 GUM_CONS_MOV(DBCell);
106 INLINE DBCell::~DBCell() {
107 GUM_DESTRUCTOR(DBCell);
112 INLINE DBCell& DBCell::operator=(
const DBCell& from) {
114 _type_ = from._type_;
115 std::memcpy(&_val_index_, &(from._val_index_),
sizeof(UnionType));
122 INLINE DBCell& DBCell::operator=(DBCell&& from) {
124 _type_ = from._type_;
125 std::memcpy(&_val_index_, &(from._val_index_),
sizeof(UnionType));
132 INLINE DBCell& DBCell::operator=(
const float x) {
133 _type_ = EltType::REAL;
139 INLINE DBCell& DBCell::operator=(
const int x) {
140 _type_ = EltType::INTEGER;
146 INLINE DBCell& DBCell::operator=(
const std::string& str) {
147 if (!_strings_().existsFirst(str)) {
148 _strings_().insert(str, _string_max_index_);
149 _val_index_ = _string_max_index_;
150 ++_string_max_index_;
152 _val_index_ = _strings_().second(str);
154 _type_ = EltType::STRING;
160 INLINE
bool DBCell::operator==(
const DBCell& from)
const {
161 return (_type_ == from._type_)
162 && ((_type_ == EltType::MISSING)
163 || ((_type_ == EltType::REAL) && (_val_real_ == from._val_real_))
164 || (_val_integer_ == from._val_integer_));
168 INLINE DBCell::EltType DBCell::type() const noexcept {
return _type_; }
171 INLINE
float DBCell::real()
const {
172 if (_type_ == EltType::REAL)
return _val_real_;
177 INLINE
void DBCell::setReal(
const float x) {
178 _type_ = EltType::REAL;
183 INLINE
void DBCell::setReal(std::string_view elt) {
185 _val_real_ =
std::stof(
std::
string(elt));
186 _type_ = EltType::REAL;
190 INLINE
int DBCell::integer()
const {
191 if (_type_ == EltType::INTEGER)
return _val_integer_;
196 INLINE
void DBCell::setInteger(
const int x) {
197 _type_ = EltType::INTEGER;
202 INLINE
void DBCell::setInteger(std::string_view elt) {
204 _val_integer_ =
std::stoi(
std::
string(elt));
205 _type_ = EltType::INTEGER;
209 INLINE const
std::
string& DBCell::
string()
const {
210 if (_type_ == EltType::STRING)
return _strings_().first(_val_index_);
215 INLINE
int DBCell::stringIndex()
const {
216 if (_type_ == EltType::STRING)
return _val_index_;
221 INLINE
const std::string& DBCell::string(
const int index) {
return _strings_().first(index); }
224 INLINE
void DBCell::setString(
const std::string& str) {
225 if (!_strings_().existsFirst(str)) {
226 _strings_().insert(str, _string_max_index_);
227 _val_index_ = _string_max_index_;
228 ++_string_max_index_;
230 _val_index_ = _strings_().second(str);
232 _type_ = EltType::STRING;
236 INLINE
void DBCell::setMissingState() { _type_ = EltType::MISSING; }
239 INLINE
bool DBCell::isMissing()
const {
return _type_ == EltType::MISSING; }
242 INLINE
bool DBCell::isMissing(std::string_view str,
243 const std::vector< std::string >& missingVals) {
244 for (
const auto& missing: missingVals) {
245 if (str == missing)
return true;
251 INLINE DBCell::EltType DBCell::bestType(std::string_view str,
252 const std::vector< std::string >& missingVals) {
253 if (isMissing(str, missingVals))
return EltType::MISSING;
254 if (
isInteger(str))
return EltType::INTEGER;
255 if (isReal(str))
return EltType::REAL;
256 return EltType::STRING;
260 INLINE DBCell DBCell::bestDBCell(std::string_view str,
261 const std::vector< std::string >& missingVals) {
262 if (isMissing(str, missingVals))
return {};
263 if (
isInteger(str))
return DBCell(std::stoi(std::string(str)));
264 if (isReal(str))
return DBCell(std::stof(std::string(str)));
266 return DBCell(std::string(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(std::string_view 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