Turi Create
4.0
|
Global configuration manager that allows config to be set by environment variables. More...
Classes | |
struct | turi::globals::register_global< int64_t > |
struct | turi::globals::register_global< double > |
struct | turi::globals::register_global< std::string > |
Macros | |
#define | REGISTER_GLOBAL(type, varname, runtime_modifiable) |
#define | REGISTER_GLOBAL_WITH_CHECKS(type, varname, runtime_modifiable, lambda) |
Enumerations | |
enum | turi::globals::set_global_error_codes |
Functions | |
flexible_type | turi::globals::get_global (std::string name) |
set_global_error_codes | turi::globals::set_global (std::string name, flexible_type val) |
void | turi::globals::initialize_globals_from_environment (std::string root_path) |
Global configuration manager that allows config to be set by environment variables.
#define REGISTER_GLOBAL | ( | type, | |
varname, | |||
runtime_modifiable | |||
) |
Register a global variable.
type | The type of the variable. Must be integral, string, or double. |
varname | The variable name. This variable can then be modified by setting the environment variable with the same name as the variable ( prefixxed with TURI_) |
runtime_modifiable | If false, this variable can only be modified by setting an environment variable. If true, it can be changed at runtime to any value. |
Example: REGISTER_GLOBAL(size_t, GLOBAL_PIKA_PIKA, false)
Then setting the environment variable TURI_GLOBAL_PIKA_PIKA will change the value of the variable.
REGISTER_GLOBAL(size_t, GLOBAL_PIKA_PIKA, true)
Will allow the variable to be modified at runtime via Python.
Definition at line 188 of file globals.hpp.
#define REGISTER_GLOBAL_WITH_CHECKS | ( | type, | |
varname, | |||
runtime_modifiable, | |||
lambda | |||
) |
Register a global variable with value checking.
type | The type of the variable. Must be integral, string, or double. |
varname | The variable name. This variable can then be modified by setting the environment variable with the same name as the variable ( prefixxed with TURI_) |
runtime_modifiable | If false, this variable can only be modified by setting an environment variable. If true, it can be changed at runtime to any value. |
lambda | A function pointer / lambda function which checks the value when a value change is requested. The function should take a single input of the new value, and return a boolean value. (true for good, and false for bad). This lambda should be self contained and should not be dependent on other global objects since this will cause order of construction/destruction issues. |
Example: REGISTER_GLOBAL_WITH_CHECKS(size_t, GLOBAL_PIKA_PIKA, false. +[](size_t i){ return i >= 1024})
Then setting the environment variable TURI_GLOBAL_PIKA_PIKA will change the value of the variable but it will only succeed if the value is greater than 1024.
REGISTER_GLOBAL(size_t, GLOBAL_PIKA_PIKA, true)
Will allow the variable to be modified at runtime via Python But the change will only succeed if the value is greater than 1024.
Definition at line 227 of file globals.hpp.
|
strong |
Global assignment error codes
Definition at line 141 of file globals.hpp.
flexible_type turi::globals::get_global | ( | std::string | name | ) |
Gets a value of a single global value. There are a few builtins. UNITY_SERVER_BINARY: The location of the unity_server executable (for instance ./unity_server) UNITY_SERVER_PATH: The path of the unity_server executable (for instance
void turi::globals::initialize_globals_from_environment | ( | std::string | root_path | ) |
Initialize all registered global variables from environment variables. Also initializes the globals GLOBALS_MAIN_PROCESS_PATH from root_path which is the root directory of installation
set_global_error_codes turi::globals::set_global | ( | std::string | name, |
flexible_type | val | ||
) |
Sets a modifiable global value. Return set_global_error_codes::SUCCESS (0) on success and otherwise on failure.