37 #include <unordered_map>
50 VariableInfo variable_info[] = {
55 typedef std::unordered_map<int, const char *> CodeToStringMap;
57 CodeToStringMap &build_code_to_string_map() {
58 CodeToStringMap *map =
new CodeToStringMap();
59 for (
int i=0; variable_info[i].text != 0; i++)
60 (*map)[variable_info[i].code] = variable_info[i].text;
65 CodeToStringMap &code_to_string_map = build_code_to_string_map();
67 typedef std::unordered_map<String, int> StringToCodeMap;
69 StringToCodeMap &build_string_to_code_map() {
70 StringToCodeMap *map =
new StringToCodeMap();
71 for (
int i=0; variable_info[i].text != 0; i++)
72 (*map)[variable_info[i].text] = variable_info[i].code;
77 StringToCodeMap &string_to_code_map = build_string_to_code_map();
79 std::vector<bool> build_default_value_vector() {
80 std::vector<bool> vec;
81 for (
int i=0; variable_info[i].text != 0; i++)
82 vec.push_back(variable_info[i].default_value);
87 std::vector<bool> defaults = build_default_value_vector();
93 const char *text = code_to_string_map[var_code];
99 if (string_to_code_map.find(var_string) == string_to_code_map.end())
101 return string_to_code_map[var_string];
105 HT_ASSERT(var_code < (
int)defaults.size());
106 return defaults[var_code];
112 for (
auto &spec : specs) {
116 str += code_to_string_map[spec.code];
118 str +=
String(
"") + spec.code;
119 str +=
String(
"=") + (spec.value ?
"true" :
"false");
164 return 4 + (5 * specs.size());
169 for (
auto &spec : specs) {
176 const uint8_t **bufp,
size_t *remainp) {
179 for (
int i=0; i<count; i++) {
182 specs.push_back(spec);
std::string String
A String is simply a typedef to std::string.
Declarations for SystemVariable.
int32_t code
Variable code.
Po::typed_value< String > * str(String *v=0)
bool default_value(int var_code)
Returns default value for given variable.
std::string specs_to_string(const std::vector< Spec > &specs)
Returns a textual representation of variable specifications.
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
int string_to_code(const std::string &var_string)
Converts variable string to variable code.
void decode_specs(std::vector< Spec > &specs, const uint8_t **bufp, size_t *remainp)
Decodes a vector of variable specs.
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
Logging routines and macros.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
void encode_specs(const std::vector< Spec > &specs, uint8_t **bufp)
Encodes a vector of variable specs.
Functions to serialize/deserialize primitives to/from a memory buffer.
size_t encoded_length_internal() const override
Returns internal serialized length.
Holds a variable code and boolean value.
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
void encode_bool(uint8_t **bufp, bool bval)
Encodes a boolean into the given buffer.
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
uint8_t encoding_version() const override
Returns encoding version.
A String class based on std::string.
bool value
Variable value.
String extensions and helpers: sets, maps, append operators etc.
size_t encoded_length_specs(const std::vector< Spec > &specs)
Returns encoded length of variable specs vector.
const char * code_to_string(int var_code)
Converts variable code to variable string.