Turi Create  4.0
Global Parameter Registration

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)
 

Detailed Description

Global configuration manager that allows config to be set by environment variables.

Macro Definition Documentation

◆ REGISTER_GLOBAL

#define REGISTER_GLOBAL (   type,
  varname,
  runtime_modifiable 
)
Value:
static auto __ ## varname ## __register__ ## instance = \
::turi::globals::register_global \
<type>("TURI_" #varname, \
(type*)(&varname), \
runtime_modifiable);

Register a global variable.

Parameters
typeThe type of the variable. Must be integral, string, or double.
varnameThe variable name. This variable can then be modified by setting the environment variable with the same name as the variable ( prefixxed with TURI_)
runtime_modifiableIf 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.

◆ REGISTER_GLOBAL_WITH_CHECKS

#define REGISTER_GLOBAL_WITH_CHECKS (   type,
  varname,
  runtime_modifiable,
  lambda 
)
Value:
static auto __ ## varname ## __register__ ## instance = \
::turi::globals::register_global \
<type>("TURI_" #varname, \
(type*)(&varname), \
runtime_modifiable, \
lambda);

Register a global variable with value checking.

Parameters
typeThe type of the variable. Must be integral, string, or double.
varnameThe variable name. This variable can then be modified by setting the environment variable with the same name as the variable ( prefixxed with TURI_)
runtime_modifiableIf false, this variable can only be modified by setting an environment variable. If true, it can be changed at runtime to any value.
lambdaA 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.

Enumeration Type Documentation

◆ set_global_error_codes

Global assignment error codes

Definition at line 141 of file globals.hpp.

Function Documentation

◆ get_global()

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

◆ initialize_globals_from_environment()

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()

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.