RIT VEXU Core API
Loading...
Searching...
No Matches
Serializer Class Reference

Serializes Arbitrary data to a file on the SD Card. More...

#include <serializer.h>

Public Member Functions

 ~Serializer ()
 Save and close upon destruction (bc of vex, this doesnt always get called when the program ends. To be sure, call save_to_disk)
 
 Serializer (const std::string &filename, bool flush_always=true)
 create a Serializer
 
void save_to_disk () const
 saves current Serializer state to disk
 
void set_int (const std::string &name, int i)
 Setters - not saved until save_to_disk is called.
 
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
 
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
 
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
 
int int_or (const std::string &name, int otherwise)
 gets a value stored in the serializer. If not found, sets the value to otherwise
 
bool bool_or (const std::string &name, bool otherwise)
 gets a value stored in the serializer. If not, sets the value to otherwise
 
double double_or (const std::string &name, double otherwise)
 gets a value stored in the serializer. If not, sets the value to otherwise
 
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
 

Detailed Description

Serializes Arbitrary data to a file on the SD Card.

Constructor & Destructor Documentation

◆ Serializer()

Serializer::Serializer ( const std::string & filename,
bool flush_always = true )
inlineexplicit

create a Serializer

Parameters
filenamethe file to read from. If filename does not exist we will create that file
flush_alwaysIf true, after every write flush to a file. If false, you are responsible for calling save_to_disk

Member Function Documentation

◆ bool_or()

bool Serializer::bool_or ( const std::string & name,
bool otherwise )

gets a value stored in the serializer. If not, sets the value to otherwise

Parameters
namename of value
otherwisevalue if the name is not specified
Returns
the value if found or otherwise

◆ double_or()

double Serializer::double_or ( const std::string & name,
double otherwise )

gets a value stored in the serializer. If not, sets the value to otherwise

Parameters
namename of value
otherwisevalue if the name is not specified
Returns
the value if found or otherwise

◆ int_or()

int Serializer::int_or ( const std::string & name,
int otherwise )

gets a value stored in the serializer. If not found, sets the value to otherwise

Getters Return value if it exists in the serializer

Parameters
namename of value
otherwisevalue if the name is not specified
Returns
the value if found or otherwise

◆ save_to_disk()

void Serializer::save_to_disk ( ) const

saves current Serializer state to disk

forms data bytes then saves to filename this was openned with

◆ set_bool()

void Serializer::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

Parameters
namename of bool
bvalue of bool

◆ set_double()

void Serializer::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

Parameters
namename of double
dvalue of double

◆ set_int()

void Serializer::set_int ( const std::string & name,
int i )

Setters - not saved until save_to_disk is called.

sets an integer by the name of name to i. If flush_always == true, this will save to the sd card

Parameters
namename of integer
ivalue of integer

◆ set_string()

void Serializer::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

Parameters
namename of string
ivalue of string

◆ string_or()

std::string Serializer::string_or ( const std::string & name,
std::string otherwise )

gets a value stored in the serializer. If not, sets the value to otherwise

Parameters
namename of value
otherwisevalue if the name is not specified
Returns
the value if found or otherwise

The documentation for this class was generated from the following files: