10const char serialization_separator =
'$';
12const std::size_t MAX_FILE_SIZE = 4096;
19 std::map<std::string, int> ints;
20 std::map<std::string, bool> bools;
21 std::map<std::string, double> doubles;
22 std::map<std::string, std::string> strings;
25 bool read_from_disk();
32 printf(
"Saving %s\n", filename.c_str());
40 explicit Serializer(
const std::string &filename,
bool flush_always =
true)
41 : flush_always(flush_always), filename(filename), ints({}), bools({}), doubles({}), strings({})
55 void set_int(
const std::string &name,
int i);
60 void set_bool(
const std::string &name,
bool b);
65 void set_double(
const std::string &name,
double d);
70 void set_string(
const std::string &name, std::string str);
79 int int_or(
const std::string &name,
int otherwise);
85 bool bool_or(
const std::string &name,
bool otherwise);
91 double double_or(
const std::string &name,
double otherwise);
97 std::string
string_or(
const std::string &name, std::string otherwise);
Serializes Arbitrary data to a file on the SD Card.
Definition serializer.h:15
double double_or(const std::string &name, double otherwise)
gets a value stored in the serializer. If not, sets the value to otherwise
Definition serializer.cpp:147
void set_bool(const std::string &name, bool b)
sets a bool by the name of name to b. If flush_always == true, this will save to the sd card
Definition serializer.cpp:114
Serializer(const std::string &filename, bool flush_always=true)
create a Serializer
Definition serializer.h:40
bool bool_or(const std::string &name, bool otherwise)
gets a value stored in the serializer. If not, sets the value to otherwise
Definition serializer.cpp:140
void set_double(const std::string &name, double d)
sets a double by the name of name to d. If flush_always == true, this will save to the sd card
Definition serializer.cpp:120
~Serializer()
Save and close upon destruction (bc of vex, this doesnt always get called when the program ends....
Definition serializer.h:30
std::string string_or(const std::string &name, std::string otherwise)
gets a value stored in the serializer. If not, sets the value to otherwise
Definition serializer.cpp:154
int int_or(const std::string &name, int otherwise)
gets a value stored in the serializer. If not found, sets the value to otherwise
Definition serializer.cpp:133
void save_to_disk() const
saves current Serializer state to disk
Definition serializer.cpp:163
void set_int(const std::string &name, int i)
Setters - not saved until save_to_disk is called.
Definition serializer.cpp:108
void set_string(const std::string &name, std::string str)
sets a string by the name of name to s. If flush_always == true, this will save to the sd card
Definition serializer.cpp:126