-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue.hpp
73 lines (65 loc) · 1.62 KB
/
value.hpp
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
// Author: Kristi Daigh
// Project: MLEM2 Rule Induction
// Date: 11/20/2019
/** Header file for the attribute-value class.
@file value.hpp */
#ifndef VALUE_H
#define VALUE_H
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
enum Type {
SYMBOLIC, NUMERIC
};
class Value {
public:
Value(string strValue) : m_strValue(strValue) {
stringstream stream (strValue);
if(isNumber(strValue)){
stream >> m_numValue;
m_type = NUMERIC;
} else {
m_type = SYMBOLIC;
}
}
string getStrValue() const{
return m_strValue;
}
float getNumValue() const{
return m_numValue;
}
bool isNumeric() const{
if(m_type == NUMERIC){
return true;
}
return false;
}
bool isNumber(std::string str) const {
// Check for symbolic ranges (i.e. "40-49")
size_t pos = str.find("-");
if(pos != string::npos){
// Dash is not the first character (it's a symbolic range)
if(pos != 0){
return false;
}
}
// Check for symbolic ranges (i.e. "40..49")
if(str.find("..") != string::npos){
return false;
}
// Check for non-numeric characters
string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ[]{};:,/?=~|";
for(char c : chars){
if(str.find(c) != string::npos){
return false;
}
}
return true;
}
private:
string m_strValue;
float m_numValue;
Type m_type;
};
#endif