forked from openframeworks/openFrameworks
/
ofParameter.cpp
133 lines (99 loc) · 2.66 KB
/
ofParameter.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
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
#include "ofParameter.h"
#include "ofParameterGroup.h"
using namespace std;
string ofAbstractParameter::getEscapedName() const{
return escape(getName());
}
string ofAbstractParameter::escape(const string& _str) const{
std::string str(_str);
ofStringReplace(str, " ", "_");
ofStringReplace(str, "<", "_");
ofStringReplace(str, ">", "_");
ofStringReplace(str, "{", "_");
ofStringReplace(str, "}", "_");
ofStringReplace(str, "[", "_");
ofStringReplace(str, "]", "_");
ofStringReplace(str, ",", "_");
ofStringReplace(str, "(", "_");
ofStringReplace(str, ")", "_");
ofStringReplace(str, "/", "_");
ofStringReplace(str, "\\", "_");
ofStringReplace(str, ".", "_");
return str;
}
string ofAbstractParameter::type() const{
return typeid(*this).name();
}
vector<string> ofAbstractParameter::getGroupHierarchyNames() const{
vector<string> hierarchy;
auto p = getFirstParent();
if(p){
hierarchy = p.getGroupHierarchyNames();
}
hierarchy.push_back(getEscapedName());
return hierarchy;
}
bool ofAbstractParameter::isReferenceTo(const ofAbstractParameter &other) const{
return getInternalObject() == other.getInternalObject();
}
ostream& operator<<(ostream& os, const ofAbstractParameter& p){
os << p.toString();
return os;
}
istream& operator>>(istream& is, ofAbstractParameter& p){
string str;
is >> str;
p.fromString(str);
return is;
}
ofParameter<void>::ofParameter()
:obj(new Value){
}
ofParameter<void>::ofParameter(const string& name)
:obj(new Value(name)){
}
void ofParameter<void>::setName(const string & name){
obj->name = name;
}
string ofParameter<void>::getName() const{
return obj->name;
}
std::string ofParameter<void>::toString() const{
return "";
}
void ofParameter<void>::fromString(const std::string & name){
}
ofParameter<void>& ofParameter<void>::set(const std::string & name){
setName(name);
return *this;
}
void ofParameter<void>::trigger(){
ofNotifyEvent(obj->changedE,this);
}
void ofParameter<void>::enableEvents(){
obj->changedE.enable();
}
void ofParameter<void>::disableEvents(){
obj->changedE.disable();
}
bool ofParameter<void>::isSerializable() const{
return obj->serializable;
}
bool ofParameter<void>::isReadOnly() const{
return false;
}
void ofParameter<void>::makeReferenceTo(ofParameter<void> & mom){
*this = mom;
}
void ofParameter<void>::setSerializable(bool serializable){
obj->serializable = serializable;
}
shared_ptr<ofAbstractParameter> ofParameter<void>::newReference() const{
return std::make_shared<ofParameter<void>>(*this);
}
void ofParameter<void>::setParent(ofParameterGroup & parent){
obj->parents.emplace_back(parent.obj);
}
size_t ofParameter<void>::getNumListeners() const{
return obj->changedE.size();
}