-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveState.cpp
More file actions
102 lines (92 loc) · 1.38 KB
/
SaveState.cpp
File metadata and controls
102 lines (92 loc) · 1.38 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
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
/*
* SaveState.cpp
*
* Created on: Oct 17, 2016
* Author: josh
*/
#include <iostream>
#include "SaveState.h"
namespace AtomSynth
{
SaveState::SaveState()
: m_nextCounter(-1)
{
// TODO Auto-generated constructor stub
}
SaveState::SaveState(std::string from)
: m_nextCounter(-1)
{
bool isNumber = true;
double number = 0.0;
int brackets = 0;
std::string buffer = "";
SaveState state;
for(char & c : from)
{
switch(c)
{
case ':':
if(brackets == 1)
{
m_values.push_back(std::stod(buffer));
buffer = "";
}
else
{
buffer += c;
}
break;
case '[':
if(brackets == 0)
{
buffer = "";
}
else
{
buffer += '[';
}
brackets++;
break;
case ']':
buffer += ']';
brackets--;
if(brackets == 1)
{
m_states.push_back(SaveState(buffer));
buffer = "";
}
break;
default:
buffer += c;
}
}
}
SaveState::~SaveState()
{
// TODO Auto-generated destructor stub
}
SaveState & SaveState::getNextState()
{
m_nextCounter++;
if(m_nextCounter > m_states.size())
{
m_nextCounter = 0;
}
return m_states[m_nextCounter];
}
std::string SaveState::getString()
{
std::string output = "[";
for(double & value : m_values)
{
output += std::to_string(value);
output += ":";
}
for(SaveState & state : m_states)
{
output += state.getString();
}
output += ']';
return output;
}
} /* namespace AtomSynth */