|
carl
25.04
Computer ARithmetic Library
|
This class generates new variables and stores human-readable names for them. More...
#include <VariablePool.h>


Public Member Functions | |
| Variable | get_fresh_persistent_variable (VariableType type=VariableType::VT_REAL) noexcept |
| Variable | get_fresh_persistent_variable (const std::string &name, VariableType type=VariableType::VT_REAL) |
| void | clear () noexcept |
| Clears everything already created in this pool. More... | |
| Variable | find_variable_with_name (const std::string &name) const noexcept |
| Searches in the friendly names list for a variable with the given name. More... | |
| std::string | get_name (Variable v, bool variableName=true) const |
| Get a human-readable name for the given variable. More... | |
| void | set_name (Variable v, const std::string &name) |
| Add a name for a given Variable. More... | |
| void | set_prefix (std::string prefix="_") noexcept |
| Sets the prefix used when printing anonymous variables. More... | |
Static Public Member Functions | |
| static VariablePool & | getInstance () |
| Returns the single instance of this class by reference. More... | |
Protected Member Functions | |
| VariablePool () noexcept | |
| Private default constructor. More... | |
| Variable | get_fresh_variable (VariableType type=VariableType::VT_REAL) noexcept |
| Get a variable which was not used before. More... | |
| Variable | get_fresh_variable (const std::string &name, VariableType type=VariableType::VT_REAL) |
| Get a variable with was not used before and set a name for it. More... | |
Private Member Functions | |
| std::size_t & | nextID (VariableType vt) noexcept |
| std::size_t | nextID (VariableType vt) const noexcept |
Private Attributes | |
| friend | Singleton< VariablePool > |
| std::array< std::size_t, static_cast< std::size_t >VariableType::TYPE_SIZE)> | mNextIDs |
| Contains the id of the next variable to be created for each type. More... | |
| std::mutex | freshVarMutex |
| Mutex for calling get_fresh_variable(). More... | |
| std::mutex | set_nameMutex |
| Mutex for calling setVariableName(). More... | |
| std::vector< std::pair< Variable, std::string > > | mPersistentVariables |
| Contains persistent variables that are restored after clear was called. More... | |
| std::map< Variable, std::string > | mVariableNames |
| Stores human-readable names for variables that can be set via setVariableName(). More... | |
| std::string | mVariablePrefix |
| Stores a prefix for printing variables that have no human-readable name. More... | |
Friends | |
| Variable | fresh_variable (VariableType vt) noexcept |
| Variable | fresh_variable (const std::string &name, VariableType vt) |
This class generates new variables and stores human-readable names for them.
As we want only a single unique VariablePool and need global access to it, it is implemented as a singleton.
All methods that modify the pool, that are getInstance(), get_fresh_variable() and set_name(), are thread-safe.
Definition at line 27 of file VariablePool.h.
|
protectednoexcept |
Private default constructor.
Definition at line 15 of file VariablePool.cpp.

|
inlinenoexcept |
Clears everything already created in this pool.
Definition at line 109 of file VariablePool.h.


|
noexcept |
Searches in the friendly names list for a variable with the given name.
| name | The friendly variable name to look for. |
Definition at line 56 of file VariablePool.cpp.

| Variable carl::VariablePool::get_fresh_persistent_variable | ( | const std::string & | name, |
| VariableType | type = VariableType::VT_REAL |
||
| ) |
|
noexcept |
Definition at line 40 of file VariablePool.cpp.


|
protected |
Get a variable with was not used before and set a name for it.
This method is thread-safe.
| name | Name for the new variable. |
| type | Type for the new variable. |
Definition at line 31 of file VariablePool.cpp.

|
protectednoexcept |
Get a variable which was not used before.
This method is thread-safe.
| type | Type for the new variable. |
Definition at line 21 of file VariablePool.cpp.

| std::string carl::VariablePool::get_name | ( | Variable | v, |
| bool | variableName = true |
||
| ) | const |
Get a human-readable name for the given variable.
If the given Variable is Variable::NO_VARIABLE, "NO_VARIABLE" is returned. If friendlyVarName is true, the name that was set via setVariableName() for this Variable, if there is any, is returned. Otherwise "x_<id>" is returned, id being the internal id of the Variable.
| v | Variable. |
| variableName | Flag, if a name set via setVariableName shall be considered. |
Definition at line 63 of file VariablePool.cpp.


|
inlinestaticinherited |
Returns the single instance of this class by reference.
If there is no instance yet, a new one is created.
Definition at line 45 of file Singleton.h.
|
inlineprivatenoexcept |
Definition at line 51 of file VariablePool.h.
|
inlineprivatenoexcept |
| void carl::VariablePool::set_name | ( | Variable | v, |
| const std::string & | name | ||
| ) |
Add a name for a given Variable.
This method is thread-safe.
| v | Variable. |
| name | Some string naming the variable. |
Definition at line 90 of file VariablePool.cpp.

|
inlinenoexcept |
Sets the prefix used when printing anonymous variables.
The default is "_", hence they look like "_x_5".
| prefix | Prefix for anonymous variable names. |
Definition at line 154 of file VariablePool.h.

|
friend |
Definition at line 182 of file VariablePool.h.
|
friend |
Definition at line 179 of file VariablePool.h.
|
mutableprivate |
Mutex for calling get_fresh_variable().
Definition at line 40 of file VariablePool.h.
|
private |
Contains the id of the next variable to be created for each type.
As such, is also a counter of the variables that exist.
Definition at line 35 of file VariablePool.h.
|
private |
Contains persistent variables that are restored after clear was called.
Definition at line 59 of file VariablePool.h.
|
private |
Stores human-readable names for variables that can be set via setVariableName().
Definition at line 64 of file VariablePool.h.
|
private |
Stores a prefix for printing variables that have no human-readable name.
Definition at line 69 of file VariablePool.h.
|
mutableprivate |
Mutex for calling setVariableName().
Definition at line 45 of file VariablePool.h.
|
private |
Definition at line 28 of file VariablePool.h.