Newer
Older
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
// [cfg-var.h]:
// -------------------------------------------------------------------------------------------- //
// configurable variable class 'cfgValue'
// -------------------------------------------------------------------------------------------- //
#define _CRT_SECURE_NO_WARNINGS
#include <string>
namespace scm
{
bool is_integer(const char* token, int* value);
bool is_integer(const char* token);
bool is_double(const char* token, double* value);
bool is_double(const char* token);
bool is_valid_c_name(const char* token);
bool is_valid_string(const char* string);
bool is_boolean(const char* token, bool* value);
bool is_boolean(const char* token);
// --- copy a = b and remove [sym]
void strcpyrm(char* a, const char* b, const char sym);
// -------------------------------------------------------------------------------------------- //
class cfgValue {
public:
enum VAR_TYPE { IS_UNDEF, IS_INT, IS_DOUBLE, IS_STRING, IS_BOOLEAN };
// -------------------------------------------------------------------------------------------- //
cfgValue();
cfgValue(const int x);
cfgValue(const float x);
cfgValue(const double x);
cfgValue(const long double x);
cfgValue(const char* c_str);
cfgValue(const bool x);
~cfgValue();
// -------------------------------------------------------------------------------------------- //
// -------------------------------------------------------------------------------------------- //
cfgValue(const cfgValue& x);
const cfgValue& operator=(cfgValue x);
void swap(cfgValue& x);
// -------------------------------------------------------------------------------------------- //
// --- assuming that string should be in double quotation marks ""
static cfgValue make_implicit(const char* x_in_string);
// -------------------------------------------------------------------------------------------- //
// clear --> type = IS_UNDEF
// -------------------------------------------------------------------------------------------- //
void clear();
// -------------------------------------------------------------------------------------------- //
// get & check calls
// -------------------------------------------------------------------------------------------- //
bool get(int* x) const;
bool get(float* x) const;
bool get(double* x) const;
bool get(long double* x) const;
bool get(char** c_str) const;
bool get(std::string& x) const;
bool get(bool* x) const;
VAR_TYPE get_type() const;
// : type != IS_UNDEF
bool is_defined() const;
// -------------------------------------------------------------------------------------------- //
// print
// -------------------------------------------------------------------------------------------- //
void print(FILE *ptr) const;
void print() const;
void print_typed() const;
// -------------------------------------------------------------------------------------------- //
// operators
// -------------------------------------------------------------------------------------------- //
cfgValue& operator+=(const cfgValue& x);
cfgValue& operator-=(const cfgValue& x);
cfgValue& operator*=(const cfgValue& x);
cfgValue& operator/=(const cfgValue& x);
cfgValue& operator%=(const cfgValue& x);
cfgValue& operator^=(const cfgValue& x);
const cfgValue operator+(const cfgValue& x) const;
const cfgValue operator-(const cfgValue& x) const;
const cfgValue operator*(const cfgValue& x) const;
const cfgValue operator/(const cfgValue& x) const;
const cfgValue operator%(const cfgValue& x) const;
const cfgValue operator^(const cfgValue& x) const;
const cfgValue operator==(const cfgValue& x) const;
const cfgValue operator!=(const cfgValue& x) const;
const cfgValue operator<(const cfgValue& x) const;
const cfgValue operator>(const cfgValue& x) const;
const cfgValue operator<=(const cfgValue& x) const;
const cfgValue operator>=(const cfgValue& x) const;
const cfgValue operator-() const;
const cfgValue operator+() const;
const cfgValue logical_and(const cfgValue& x) const; // no short-circuit
const cfgValue logical_or(const cfgValue& y) const; // no short-circuit
// -------------------------------------------------------------------------------------------- //
// functions
// -------------------------------------------------------------------------------------------- //
static const cfgValue cfg_sin(const cfgValue& x);
static const cfgValue cfg_cos(const cfgValue& x);
static const cfgValue cfg_tan(const cfgValue& x);
static const cfgValue cfg_log(const cfgValue& x);
static const cfgValue cfg_sqrt(const cfgValue& x);
static const cfgValue cfg_abs(const cfgValue& x);
static const cfgValue cfg_to_string(const cfgValue& x);
static const cfgValue cfg_min(const cfgValue& a, const cfgValue& b);
static const cfgValue cfg_max(const cfgValue& a, const cfgValue& b);
// -------------------------------------------------------------------------------------------- //
private:
// data (private):
// -------------------------------------------------------------------------------------------- //
VAR_TYPE type;
int eint;
double edouble;
char *estring;
bool ebool;
};
}
// -------------------------------------------------------------------------------------------- //