forked from jasp-stats/jasp-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemptyvalues.cpp
95 lines (74 loc) · 2.21 KB
/
emptyvalues.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "emptyvalues.h"
#include "columnutils.h"
#include "log.h"
#include "jsonutilities.h"
std::string EmptyValues::_displayString = "";
const int EmptyValues::missingValueInteger = std::numeric_limits<int>::lowest();
const double EmptyValues::missingValueDouble = NAN;
EmptyValues::EmptyValues(EmptyValues * parent) : _parent(parent)
{
//Log::log() << "EmptyValues::EmptyValues(" << (parent ? "a parent" : "null") << ");" << std::endl;
}
void EmptyValues::resetEmptyValues()
{
_emptyStrings.clear();
_emptyDoubles.clear();
}
EmptyValues::~EmptyValues()
{
}
Json::Value EmptyValues::toJson() const
{
Json::Value emptyVals = Json::objectValue;
emptyVals["strings"] = JsonUtilities::setToJsonArray(_emptyStrings);
emptyVals["custom"] = _hasEmptyValues;
return emptyVals;
}
void EmptyValues::fromJson(const Json::Value & json)
{
resetEmptyValues();
if (!json.isObject())
return;
setEmptyValues( JsonUtilities::jsonStringArrayToSet(json["strings"] ),
json["custom"].asBool() );
}
const stringset& EmptyValues::emptyStrings() const
{
return _emptyStrings;
}
const stringset &EmptyValues::emptyStringsColumnModel() const
{
return !_parent ? _emptyStrings : !_hasEmptyValues ? _parent->_emptyStrings : _emptyStrings;
}
const doubleset & EmptyValues::emptyDoubles() const
{
return _emptyDoubles;
}
void EmptyValues::setEmptyValues(const stringset &values)
{
setEmptyValues(values, values.size());
}
void EmptyValues::setEmptyValues(const stringset& values, bool custom)
{
_emptyStrings = values;
_emptyDoubles = ColumnUtils::getDoubleValues(values);
_hasEmptyValues = custom;
}
bool EmptyValues::hasEmptyValues() const
{
return !_parent || _hasEmptyValues;
}
void EmptyValues::setHasCustomEmptyValues(bool hasThem)
{
_hasEmptyValues = hasThem;
if(_parent)
setEmptyValues(!_hasEmptyValues ? stringset() : _parent->_emptyStrings, _hasEmptyValues);
}
bool EmptyValues::isEmptyValue(const std::string& val) const
{
return hasEmptyValues() ? _emptyStrings.count(val) : ( _parent && _parent->isEmptyValue(val));
}
bool EmptyValues::isEmptyValue(const double val) const
{
return hasEmptyValues() ? std::isnan(val) || _emptyDoubles.count(val) : ( _parent && _parent->isEmptyValue(val));
}