PeriDyno 1.0.0
Loading...
Searching...
No Matches
FSerialization.inl
Go to the documentation of this file.
1#include "Field.h"
2
3namespace dyno
4{
5 template<>
6 inline std::string FVar<bool>::serialize()
7 {
8 if (isEmpty())
9 return "";
10
11 bool b = this->getValue();
12 return b ? "true" : "false";
13 }
14
15 template<>
16 inline bool FVar<bool>::deserialize(const std::string& str)
17 {
18 if (str.empty())
19 return false;
20
21 bool b = str == std::string("true") ? true : false;
22 this->setValue(b);
23
24 return true;
25 }
26
27 template<>
28 inline std::string FVar<int>::serialize()
29 {
30 if (isEmpty())
31 return "";
32
33 int val = this->getValue();
34
35 std::stringstream ss;
36 ss << val;
37
38 return ss.str();
39 }
40
41 template<>
42 inline bool FVar<int>::deserialize(const std::string& str)
43 {
44 if (str.empty())
45 return false;
46
47 int val = std::stoi(str);
48 this->setValue(val);
49
50 return true;
51 }
52
53 template<>
54 inline std::string FVar<uint>::serialize()
55 {
56 if (isEmpty())
57 return "";
58
59 uint val = this->getValue();
60
61 std::stringstream ss;
62 ss << val;
63
64 return ss.str();
65 }
66
67 template<>
68 inline bool FVar<uint>::deserialize(const std::string& str)
69 {
70 if (str.empty())
71 return false;
72
73 uint val = std::stoi(str);
74 this->setValue(val);
75
76 return true;
77 }
78
79 template<>
80 inline std::string FVar<float>::serialize()
81 {
82 if (isEmpty())
83 return "";
84
85 float val = this->getValue();
86
87 std::stringstream ss;
88 ss << val;
89
90 return ss.str();
91 }
92
93 template<>
94 inline bool FVar<float>::deserialize(const std::string& str)
95 {
96 if (str.empty())
97 return false;
98
99 float val = std::stof(str);
100 this->setValue(val);
101
102 return true;
103 }
104
105 template<>
106 inline std::string FVar<double>::serialize()
107 {
108 if (isEmpty())
109 return "";
110
111 double val = this->getValue();
112
113 std::stringstream ss;
114 ss << val;
115
116 return ss.str();
117 }
118
119 template<>
120 inline bool FVar<double>::deserialize(const std::string& str)
121 {
122 if (str.empty())
123 return false;
124
125 double val = std::stod(str);
126 this->setValue(val);
127
128 return true;
129 }
130
131 template<>
132 inline std::string FVar<Vec3f>::serialize()
133 {
134 if (isEmpty())
135 return "";
136
137 Vec3f val = this->getValue();
138
139 std::stringstream ss;
140 ss << val.x << " " << val.y << " " << val.z;
141
142 return ss.str();
143 }
144
145 template<>
146 inline bool FVar<Vec3f>::deserialize(const std::string& str)
147 {
148 if (str.empty())
149 return false;
150
151 std::stringstream ss(str);
152 std::string substr;
153
154 ss >> substr;
155 float x = std::stof(substr);
156
157 ss >> substr;
158 float y = std::stof(substr);
159
160 ss >> substr;
161 float z = std::stof(substr);
162
163
164 this->setValue(Vec3f(x, y, z));
165
166 return true;
167 }
168
169 template<>
170 inline std::string FVar<Vec3i>::serialize()
171 {
172 if (isEmpty())
173 return "";
174
175 Vec3i val = this->getValue();
176
177 std::stringstream ss;
178 ss << val.x << " " << val.y << " " << val.z;
179
180 return ss.str();
181 }
182
183 template<>
184 inline bool FVar<Vec3i>::deserialize(const std::string& str)
185 {
186 if (str.empty())
187 return false;
188
189 std::stringstream ss(str);
190 std::string substr;
191
192 ss >> substr;
193 int x = std::stoi(substr);
194
195 ss >> substr;
196 int y = std::stoi(substr);
197
198 ss >> substr;
199 int z = std::stoi(substr.c_str());
200
201 this->setValue(Vec3i(x, y, z));
202
203 return true;
204 }
205
206 template<>
207 inline std::string FVar<Vec3d>::serialize()
208 {
209 if (isEmpty())
210 return "";
211
212 Vec3d val = this->getValue();
213
214 std::stringstream ss;
215 ss << val.x << " " << val.y << " " << val.z;
216
217 return ss.str();
218 }
219
220 template<>
221 inline bool FVar<Vec3d>::deserialize(const std::string& str)
222 {
223 if (str.empty())
224 return false;
225
226 std::stringstream ss(str);
227 std::string substr;
228
229 ss >> substr;
230 double x = std::stod(substr);
231
232 ss >> substr;
233 double y = std::stod(substr);
234
235 ss >> substr;
236 double z = std::stod(substr);
237
238 this->setValue(Vec3d(x, y, z));
239
240 return true;
241 }
242
243// template<>
244// std::string FVar<FilePath>::serialize()
245// {
246// if (isEmpty())
247// return "";
248//
249// FilePath val = this->getValue();
250//
251// return val.string();
252// }
253//
254// template<>
255// bool FVar<FilePath>::deserialize(const std::string& str)
256// {
257// if (str.empty())
258// return false;
259//
260// this->setValue(str);
261//
262// return true;
263// }
264
265 template<>
266 inline std::string FVar<std::string>::serialize()
267 {
268 if (isEmpty())
269 return "";
270
271 std::string val = this->getValue();
272
273 return val;
274 }
275
276 template<>
277 inline bool FVar<std::string>::deserialize(const std::string& str)
278 {
279 if (str.empty())
280 return false;
281
282 this->setValue(str);
283
284 return true;
285 }
286
287 template class FVar<bool>;
288 template class FVar<int>;
289 template class FVar<uint>;
290 template class FVar<float>;
291 template class FVar<double>;
292 template class FVar<Vec3f>;
293 template class FVar<Vec3d>;
294 template class FVar<Vec3i>;
295 template class FVar<std::string>;
296}
bool isEmpty() override
Definition Field.h:58
std::string serialize() override
Definition Field.h:55
bool deserialize(const std::string &str) override
Definition Field.h:56
float getValue()
Definition Field.h:130
void setValue(float val)
Definition Field.h:111
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Vector< int, 3 > Vec3i
Definition Vector3D.h:95
Vector< double, 3 > Vec3d
Definition Vector3D.h:94
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
unsigned int uint
Definition VkProgram.h:14