8#ifndef HPP_ALIB_CONFIG_CONFIGURATION
9#define HPP_ALIB_CONFIG_CONFIGURATION 1
13#include "alib/monomem/sharedmonoval.hpp"
29namespace alib {
namespace config {
33class CLIVariablesPlugin;
34class EnvironmentVariablesPlugin;
39struct ConfigNodeHandler;
220 std::equal_to<String> ,
242 std::equal_to<String> ,
257 template<
typename TVMeta>
289 const String& variableName,
291 const String& pathSubstring );
300 const String& variablePath,
397 template<
typename TVMeta>
458 template<
typename TEnum>
462 template<
typename TEnum>
489 Priority priority= Priority::DefaultValues)
501 Priority priority= Priority::DefaultValues )
563 "Event::Creation will never be invoked with this listener-registration-type.")
582 const String& variableName )
627 const String& pathPrefix )
650 const String& pathSubstring )
712 void create(
const String& typeName,
const String& defaultValue );
762 :
Cursor(cursor) {
Cursor::Value().declaration=
nullptr; create( typeName, defaultValue); }
786 :
Cursor(cfg.
Root()) { Declare( name, typeName, defaultValue ); }
798 :
Cursor(camp.GetConfig().
Root()) { Declare( name, typeName, defaultValue ); }
821 :
Cursor(camp.GetConfig().
Root()) {Declare( decl ); }
827 template<
typename TEnum>
836 template<
typename TEnum>
850 template<
typename TEnum>
854 template<
typename TEnum,
typename TEnableIf= ATMP_VOID_IF(ATMP_IS_ENUM(TEnum))>
869 template<
typename TEnum>
873 template<
typename TEnum,
typename TEnableIf= ATMP_VOID_IF(ATMP_IS_ENUM(TEnum))>
930 template<
typename TEnum>
934 template<
typename TEnum,
typename EnableIf=
951 template<
typename TEnum>
955 template<
typename TEnum>
958 Declare( TEnum
Enum, const
Box& replacements )
1077 bool Define(
Priority requestedPriority= Priority::Standard );
1176 escaper= &nonEscaper;
1177 getMeta()->exPort(
Cursor::Value().data, GetConfiguration(), *escaper, dest );
1208 "Requesting value from undeclared variable: {!Q}", *
this )
1210 "Requesting value from undefined variable. Use 'var.Define();' to mitigate\n"
1211 "this error. Variable: ", *
this )
1213 "Wrong variable type requested for variable: {!Q}.\n"
1216 *
this, getMeta()->dbgTypeID(),
typeid(T) )
1225 template<
typename T>
const T&
Get()
const
1228 "Requested value from unset variable: ", *
this )
1230 "Requesting value from undefined variable. Use 'var.Define();' to mitigate\n"
1231 "this error. Variable: ", *
this )
1233 "Wrong variable type requested for variable: {!Q}.\n"
1236 *
this, getMeta()->dbgTypeID(),
typeid(T) )
1241 operator bool () {
return Get<Bool >(); }
1243 operator float () {
return static_cast<float>(Get<double>()); }
1244 operator double () {
return Get<double >(); }
1245 operator const String& () {
return Get<AStringPA>(); }
1250 float GetFloat() {
return static_cast<float>(Get<double>()); }
1256 int Size() {
return int(Get<StringVectorPA>().size()); }
1258 bool operator= (
bool val) {
return Get<Bool >()= val; }
1260 float operator= (
float val) { Get<double >()=
static_cast<double>(val);
return val; }
1261 double operator= (
double val) {
return Get<double >()= val; }
1262 const String& operator= (
const String& val) {
return Get<AStringPA>().Reset(val); }
1276 return Get<AStringPA>();
1278 (void) Define(priority);
1279 return (Get<AStringPA>().
Reset(value));
1294 (void) Define(priority);
1295 return (Get<Bool>()= value);
1310 (void) Define(priority);
1311 return (Get<integer >()= value);
1322template<
typename TEnum>
1358template<
typename TLock>
1391 unsigned int bufferGrowthInPercent = 200,
1393 :
Base(initialBufferSizeInKB, bufferGrowthInPercent)
1395 Base::ConstructT( Base::GetAllocator(), createDefaults );
1396 DbgCriticalSections(lang::Switch::On);
1397 ALIB_DBG(Base::GetAllocator().DbgName=
"Configuration";)
1414 template<
typename TIf=
typename Base::LockType>
1418 #if ALIB_DEBUG_CRITICAL_SECTIONS
1419 if ( !Base::IsNulled() )
1421 if( onOff == lang::Switch::On ) Base::Self().NodeTable().dcs.DCSLock= &Base::GetLock();
1422 else Base::Self().NodeTable().dcs.DCSLock=
nullptr;
1429 template<
typename TIf=
typename Base::LockType>
1443 DbgCriticalSections(lang::Switch::Off);
1444 Base::Reset( Base::GetAllocator(), createDefaults );
1445 DbgCriticalSections(lang::Switch::On);
1457#if ALIB_THREADS || DOXYGEN
1477namespace APPENDABLES {
void PresetImportString(const String &name, const String &value, Priority priority=Priority::DefaultValues)
ALIB_API ~Configuration()
Destructor.
EnvironmentVariablesPlugin * environmentPlugin
A default plugin created and inserted with construction.
TypesHashTable types
A hashtable for the registered types. Key is the type name, value is the VMeta singleton.
CString SubstitutionVariableDelimiters
ALIB_API void notifyListeners(int event, const Variable &variable, const String &variablePath, Priority previousPriority)
ALIB_API std::pair< bool, int8_t > ParseBooleanToken(const String &src)
ALIB_API AString & WriteBooleanToken(bool value, int8_t index, AString &dest)
ALIB_API void registerListener(ConfigurationListener *listener, lang::ContainerOp insertOrRemove, int event, const Variable *variable, const StringTree::Cursor *subTree, const String &variableName, const String &pathPrefix, const String &pathSubstring)
ALIB_API const Declaration * StoreDeclaration(const Declaration *orig, const Box &replacements)
List< MonoAllocator, ListenerRecord > listeners
The list of registered listeners.
void PresetImportString(const String &name, const String &value, StringEscaper *escaper, Priority priority=Priority::DefaultValues)
void MonitorDistinctVariable(lang::ContainerOp insertOrRemove, ConfigurationListener *listener, ConfigurationListener::Event event, const Variable &variable)
ALIB_API bool DeletePath(const String &path)
void MonitorVariablesByName(lang::ContainerOp insertOrRemove, ConfigurationListener *listener, ConfigurationListener::Event event, const String &variableName)
alib::NumberFormat NumberFormat
void MonitorPathPrefix(lang::ContainerOp insertOrRemove, ConfigurationListener *listener, ConfigurationListener::Event event, const String &pathPrefix)
StringEscaperStandard Escaper
List< MonoAllocator, std::pair< Token, Token >, Recycling::None > BooleanTokens
void MonitorPathSubstring(lang::ContainerOp insertOrRemove, ConfigurationListener *listener, ConfigurationListener::Event event, const String &pathSubstring)
String SubstitutionVariableEnd
String SubstitutionVariableStart
friend class Variable
Type alias in namespace alib.
void MonitorPath(lang::ContainerOp insertOrRemove, ConfigurationListener *listener, ConfigurationListener::Event event, const Configuration::Cursor &cursor)
CLIVariablesPlugin * cliPlugin
A default plugin created and inserted with construction.
ALIB_API int MonitorStop(ConfigurationListener *listener)
RDHashTable replacementDeclarations
ALIB_API void presetImportString(const String &name, const String &value, const StringEscaper *escaper, Priority priority)
static const Declaration * Get(TEnum element)
const String & Name() const
TSharedConfiguration()=default
Constructs an empty instance, hence a cleared automatic pointer.
void Reset(lang::CreateDefaults createDefaults=lang::CreateDefaults::Yes)
TSharedConfiguration(std::nullptr_t) noexcept
TSharedConfiguration(size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent=200, lang::CreateDefaults createDefaults=lang::CreateDefaults::Yes)
void DbgCriticalSections(lang::Switch onOff)
Variable(lang::Camp &camp, TEnum Enum)
bool GetOrSetDefault(bool value, Priority priority=Priority::DefaultValues)
Variable(const String &name, const String &typeName, const String &defaultValue=NULL_STRING)
bool IsDefinedExternally() const
String & GetOrSetDefault(const String &value, Priority priority=Priority::DefaultValues)
Variable(lang::Camp &camp)
bool GetOrSetDefault(integer value, Priority priority=Priority::DefaultValues)
const Cursor & AsCursor() const
bool Try(const String &name)
AString & Export(AString &dest, const StringEscaper *escaper=nullptr) const
Variable(lang::Camp &camp, TEnum Enum, const Box replacements)
Variable(Configuration &cfg, TEnum Enum, const Box replacements)
Variable & Declare(TEnum Enum, const Box &replacements)
StringVectorPA & GetStrings()
Variable(Configuration &cfg, TEnum Enum)
const Declaration * GetDeclaration() const
Variable(Configuration &cfg, const Declaration *decl)
Variable(lang::Camp &camp, const Declaration *decl)
Variable & Declare(TEnum Enum)
bool IsNotDefined() const
Variable(Configuration &cfg, const String &name, const String &typeName, const String &defaultValue=NULL_STRING)
String & GetString(int idx)
Variable(Configuration &cfg)
Variable(const Cursor &cursor, const String &typeName, const String &defaultValue=NULL_STRING)
Variable(const Cursor &cursor)
AString & Name(AString &target) const
Variable(lang::Camp &camp, const String &name, const String &typeName, const String &defaultValue=NULL_STRING)
Configuration & GetConfiguration() const
Priority GetPriority() const
const Declaration * declaration
Entry()
Defaulted default constructor.
Priority priority
The priority level of this data element.
Entry(const Entry &)=delete
Deleted copy-constructor.
VMeta * meta
The virtual handler instance for this variable.
Entry(Entry &&)=delete
Deleted move-constructor.
VDATA * data
The list hook of values.
Iterator EmplaceUnique(TArgs &&... args)
SubstringType GoTo(const NameType &path)
AllocatorType & GetAllocator() noexcept
TCursor< false > Cursor
The mutable version of type StringTree::TCursor<TConst>.
config::Configuration & GetConfig()
integer IndexOf(TChar needle, integer startIdx=0) const
constexpr bool IsNotEmpty() const
#define ALIB_ASSERT_MODULE(modulename)
#define ATMP_VOID_IF(Cond)
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
#define ATMP_EQ( T, TEqual)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_ASSERT_WARNING(cond,...)
#define ATMP_T_IF(T, Cond)
CreateDefaults
Denotes whether default entities should be created or not.
@ Yes
Create default values.
@ Enabled
Caching is enabled.
@ Disabled
Caching is disabled.
Switch
Denotes if sth. is switched on or off.
@ Keep
Chooses not no clear existing data.
ContainerOp
Denotes standard container operations.
lang::basecamp::BaseCamp BASECAMP
The singleton instance of ALib Camp class BaseCamp.
config::ConfigurationListener ConfigurationListener
Type alias in namespace alib.
config::Configuration Configuration
Type alias in namespace alib.
characters::wchar wchar
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
characters::character character
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
config::Variable Variable
Type alias in namespace alib.
constexpr String NULL_STRING
A nulled string of the default character type.
lang::integer integer
Type alias in namespace alib.
virtual ~ConfigurationListener()
Virtual destructor.
Event
The type of change that imposes the notification of a listener.
@ Definition
A variable was defined or re-defined with the same or a higher priority.
@ Creation
A variable was declared for the first time.
virtual void Notify(const Variable &variable, Event event, Priority previousPriority)=0
Record used to manage registered listeners.
ConstCursorHandle subTree
If given, the subtree of variables to listen to.
AStringPA variableName
If given, the variable's name to listen to.
AStringPA pathPrefix
If given, the start string of the file path to monitor.
int event
The event to listen to.
ConstCursorHandle variable
If given, the variable to listen to.
ConfigurationListener * listener
The listener to register or dispose.
Helper-struct used for implementing field replacementDeclarations.
const String & Key(const Declaration *src) const
Helper-struct used for implementing field types.
const String Key(const VMeta *src) const
character CharacterType
The character type that the StringTree uses for child name and path strings.
static ALIB_API void FreeNode(TTree &tree, TTree::Node &node)
static void InitializeNode(TTree &tree, TTree::Node &node)
A handle type used with methods TCursor::Export and ImportCursor.
String EnumElementName
The name of the enum element.
static constexpr ForwardIterator end()
ALIB_API void operator()(TAString< nchar, lang::HeapAllocator > &target, const config::Variable &variable)
ALIB_API void operator()(TAString< wchar, lang::HeapAllocator > &target, const config::Variable &variable)
NameType key
The name to compare when just keys are used.
NameStorageType storage
The name when stored in the hashtable.