-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.cpp
More file actions
63 lines (55 loc) · 1.11 KB
/
Copy pathparse.cpp
File metadata and controls
63 lines (55 loc) · 1.11 KB
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
#include "pakDataTypes.h"
#include <sstream>
using namespace std;
void writeVec2(XMLElement* elem, string sAttributeName, vec2 vec)
{
//TODO
}
string stripCommas(string s)
{
//Replace all ',' characters with ' '
for(int i = 0; ; i++)
{
size_t iPos = s.find(',', i);
if(iPos == s.npos)
break; //Done
s.replace(iPos, 1, " ");
}
return s;
}
vec2 pointFromString(string s)
{
s = stripCommas(s);
//Now, parse
istringstream iss(s);
vec2 pt;
if(!(iss >> pt.x >> pt.y))
pt.x = pt.y = 0;
return pt;
}
string RGBToString(f32 r, f32 g, f32 b)
{
ostringstream oss;
oss << r << ", " << g << ", " << b;
return oss.str();
}
void RGBFromString(f32* r, f32* g, f32* b, string s)
{
s = stripCommas(s);
istringstream iss(s);
if(!(iss >> *r >> *g >> *b))
*r = *g = *b = 0;
}
void readVec2(XMLElement* elem, string sAttributeName, vec2* vec)
{
const char* c = elem->Attribute(sAttributeName.c_str());
if(c == NULL)
{
cout << "Err in readVec2" << endl;
vec->x = vec->y = 0;
return;
}
vec2 pt = pointFromString(c);
vec->x = pt.x;
vec->y = pt.y;
}