Skip to content

Commit a723413

Browse files
committed
Remove obsolete value assignment and operator functions
1 parent a33681e commit a723413

File tree

5 files changed

+20
-323
lines changed

5 files changed

+20
-323
lines changed

include/scratchcpp/value.h

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,18 @@ class LIBSCRATCHCPP_EXPORT Value
2222
{
2323
public:
2424
/*! Constructs a number Value. */
25-
Value(float numberValue)
26-
{
27-
value_init(&m_data);
28-
value_assign_float(&m_data, numberValue);
29-
}
30-
31-
/*! Constructs a number Value. */
32-
Value(double numberValue)
25+
Value(double numberValue = 0.0)
3326
{
3427
value_init(&m_data);
3528
value_assign_double(&m_data, numberValue);
3629
}
3730

3831
/*! Constructs a number Value. */
39-
Value(int numberValue = 0)
32+
template<typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
33+
Value(T numberValue)
4034
{
4135
value_init(&m_data);
42-
value_assign_int(&m_data, numberValue);
43-
}
44-
45-
/*! Constructs a number Value. */
46-
Value(size_t numberValue)
47-
{
48-
value_init(&m_data);
49-
value_assign_size_t(&m_data, numberValue);
50-
}
51-
52-
/*! Constructs a number Value. */
53-
Value(long numberValue)
54-
{
55-
value_init(&m_data);
56-
value_assign_long(&m_data, numberValue);
36+
value_assign_double(&m_data, numberValue);
5737
}
5838

5939
/*! Constructs a boolean Value. */
@@ -181,27 +161,16 @@ class LIBSCRATCHCPP_EXPORT Value
181161
/*! Replaces the value with modulo of the value and the given value. */
182162
void mod(const Value &v) { value_mod(&m_data, &v.m_data, &m_data); }
183163

184-
const Value &operator=(float v)
185-
{
186-
value_assign_float(&m_data, v);
187-
return *this;
188-
}
189-
190164
const Value &operator=(double v)
191165
{
192166
value_assign_double(&m_data, v);
193167
return *this;
194168
}
195169

196-
const Value &operator=(int v)
197-
{
198-
value_assign_int(&m_data, v);
199-
return *this;
200-
}
201-
202-
const Value &operator=(long v)
170+
template<typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
171+
const Value &operator=(T v)
203172
{
204-
value_assign_long(&m_data, v);
173+
value_assign_double(&m_data, v);
205174
return *this;
206175
}
207176

include/scratchcpp/value_functions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ extern "C"
1111

1212
LIBSCRATCHCPP_EXPORT void value_init(ValueData *v);
1313

14-
LIBSCRATCHCPP_EXPORT void value_assign_float(ValueData *v, float numberValue);
1514
LIBSCRATCHCPP_EXPORT void value_assign_double(ValueData *v, double numberValue);
16-
LIBSCRATCHCPP_EXPORT void value_assign_int(ValueData *v, int numberValue);
17-
LIBSCRATCHCPP_EXPORT void value_assign_size_t(ValueData *v, size_t numberValue);
18-
LIBSCRATCHCPP_EXPORT void value_assign_long(ValueData *v, long numberValue);
1915
LIBSCRATCHCPP_EXPORT void value_assign_bool(ValueData *v, bool boolValue);
2016
LIBSCRATCHCPP_EXPORT void value_assign_string(ValueData *v, const std::string &stringValue);
2117
LIBSCRATCHCPP_EXPORT void value_assign_cstring(ValueData *v, const char *stringValue);

src/scratch/value_functions.cpp

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,6 @@ extern "C"
3333

3434
/* assign */
3535

36-
/*! Assigns number of type 'float' to the given value. */
37-
void value_assign_float(ValueData *v, float numberValue)
38-
{
39-
value_free(v);
40-
41-
if (value_isInf(numberValue))
42-
v->type = ValueType::Infinity;
43-
else if (value_isNegativeInf(numberValue))
44-
v->type = ValueType::NegativeInfinity;
45-
else if (std::isnan(numberValue))
46-
v->type = ValueType::NaN;
47-
else {
48-
v->type = ValueType::Number;
49-
v->numberValue = value_floatToDouble(numberValue);
50-
}
51-
}
52-
5336
/*! Assigns number of type 'double' to the given value. */
5437
void value_assign_double(ValueData *v, double numberValue)
5538
{
@@ -67,33 +50,6 @@ extern "C"
6750
}
6851
}
6952

70-
/*! Assigns number of type 'int' to the given value. */
71-
void value_assign_int(ValueData *v, int numberValue)
72-
{
73-
value_free(v);
74-
75-
v->type = ValueType::Number;
76-
v->numberValue = numberValue;
77-
}
78-
79-
/*! Assigns number of type 'size_t' to the given value. */
80-
void value_assign_size_t(ValueData *v, size_t numberValue)
81-
{
82-
value_free(v);
83-
84-
v->type = ValueType::Number;
85-
v->numberValue = numberValue;
86-
}
87-
88-
/*! Assigns number of type 'long' to the given value. */
89-
void value_assign_long(ValueData *v, long numberValue)
90-
{
91-
value_free(v);
92-
93-
v->type = ValueType::Number;
94-
v->numberValue = numberValue;
95-
}
96-
9753
/*! Assigns boolean to the given value. */
9854
void value_assign_bool(ValueData *v, bool boolValue)
9955
{
@@ -434,7 +390,7 @@ extern "C"
434390
value_assign_double(dst, v1->numberValue + v2->numberValue);
435391
return;
436392
} else if (v1->type == ValueType::Bool && v2->type == ValueType::Bool) {
437-
value_assign_long(dst, v1->boolValue + v2->boolValue);
393+
value_assign_double(dst, v1->boolValue + v2->boolValue);
438394
return;
439395
} else if ((static_cast<int>(v1->type) < 0) || (static_cast<int>(v2->type) < 0)) {
440396
if ((v1->type == ValueType::Infinity && v2->type == ValueType::NegativeInfinity) || (v1->type == ValueType::NegativeInfinity && v2->type == ValueType::Infinity)) {
@@ -459,7 +415,7 @@ extern "C"
459415
value_assign_double(dst, v1->numberValue - v2->numberValue);
460416
return;
461417
} else if (v1->type == ValueType::Bool && v2->type == ValueType::Bool) {
462-
value_assign_long(dst, v1->boolValue - v2->boolValue);
418+
value_assign_double(dst, v1->boolValue - v2->boolValue);
463419
return;
464420
} else if ((static_cast<int>(v1->type) < 0) || (static_cast<int>(v2->type) < 0)) {
465421
if ((v1->type == ValueType::Infinity && v2->type == ValueType::Infinity) || (v1->type == ValueType::NegativeInfinity && v2->type == ValueType::NegativeInfinity)) {
@@ -484,7 +440,7 @@ extern "C"
484440
if (v1->type == ValueType::Number && v2->type == ValueType::Number)
485441
value_assign_double(dst, v1->numberValue * v2->numberValue);
486442
else if (v1->type == ValueType::Bool && v2->type == ValueType::Bool)
487-
value_assign_long(dst, v1->boolValue * v2->boolValue);
443+
value_assign_double(dst, v1->boolValue * v2->boolValue);
488444
else {
489445
const ValueType t1 = v1->type, t2 = v2->type;
490446

@@ -535,7 +491,7 @@ extern "C"
535491
value_assign_special(dst, SpecialValue::NegativeInfinity);
536492
}
537493
} else if (v2->type == ValueType::Infinity || v2->type == ValueType::NegativeInfinity) {
538-
value_assign_long(dst, 0);
494+
value_assign_double(dst, 0);
539495
} else
540496
value_assign_double(dst, value_toDouble(v1) / value_toDouble(v2));
541497
}

src/scratch/value_functions_p.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,17 @@ inline unsigned int value_digitCount(T v)
3838
return i + j;
3939
}
4040

41-
template<typename T>
42-
inline bool value_isInf(T v)
43-
{
44-
return v > 0 && std::isinf(v);
45-
}
46-
47-
template<typename T>
48-
inline bool value_isNegativeInf(T v)
49-
{
50-
return v < 0 && std::isinf(v);
51-
}
52-
5341
extern "C"
5442
{
43+
inline bool value_isInf(double v)
44+
{
45+
return v > 0 && std::isinf(v);
46+
}
47+
48+
inline bool value_isNegativeInf(double v)
49+
{
50+
return v < 0 && std::isinf(v);
51+
}
5552

5653
inline long value_convert_int_str(const char *str, int n, bool *ok)
5754
{

0 commit comments

Comments
 (0)