#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2023 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_SUPPORT_SETTINGS_MEMORYSETTINGSSTORE_H #define NUCLEX_SUPPORT_SETTINGS_MEMORYSETTINGSSTORE_H #include "Nuclex/Support/Config.h" #include "Nuclex/Support/Settings/SettingsStore.h" #include "Nuclex/Support/Variant.h" // we use Variants to store settings in memory #include // for std::unordered_map namespace Nuclex { namespace Support { namespace Settings { // ------------------------------------------------------------------------------------------- // /// Stores application settings as named properties in memory /// /// This is an implementation of the settings store that places all properties in /// memory. Useful to provide temporary settings or if the settings from another /// property store need to be modified in a transient manner. /// class NUCLEX_SUPPORT_TYPE MemorySettingsStore : public SettingsStore { /// Frees all resources owned by the memory settings store public: NUCLEX_SUPPORT_API ~MemorySettingsStore() override; /// Returns a list of all categories contained in the store /// A list of all categories present in the store currently public: NUCLEX_SUPPORT_API std::vector GetAllCategories() const override; /// Returns a list of all properties found within a category /// Name of the category whose properties will be returned /// A list of all properties present in the specified category /// /// If the root level of properties should be listed, pass an empty string as /// the category name. Specifying the name of a category that doesn't exist will /// simply return an empty list (because ) /// public: NUCLEX_SUPPORT_API std::vector GetAllProperties( const std::string &categoryName = std::string() ) const override; /// Deletes an entire category with all its properties from the store /// Name of the category that will be deleted /// True if the category existed and was deleted, false otherwise public: NUCLEX_SUPPORT_API bool DeleteCategory( const std::string &categoryName ) override; /// Deletes the specified property from the store /// /// Name of the category from which the property will be deleted /// /// Name of the property that will be deleted /// True if the property existed and was deleted, false otherwise public: NUCLEX_SUPPORT_API bool DeleteProperty( const std::string &categoryName, const std::string &propertyName ) override; /// Retrieves the value of a boolean property from the store /// Category from which the property will be read /// Name of the property whose value will be read /// The value of the requested property or nothing if it didn't exist protected: NUCLEX_SUPPORT_API std::optional RetrieveBooleanProperty( const std::string &categoryName, const std::string &propertyName ) const override; /// Retrieves the value of a 32 bit integer property from the store /// Category from which the property will be read /// Name of the property whose value will be read /// The value of the requested property or nothing if it didn't exist protected: NUCLEX_SUPPORT_API std::optional RetrieveUInt32Property( const std::string &categoryName, const std::string &propertyName ) const override; /// Retrieves the value of a 32 bit integer property from the store /// Category from which the property will be read /// Name of the property whose value will be read /// The value of the requested property or nothing if it didn't exist protected: NUCLEX_SUPPORT_API std::optional RetrieveInt32Property( const std::string &categoryName, const std::string &propertyName ) const override; /// Retrieves the value of a 64 bit integer property from the store /// Category from which the property will be read /// Name of the property whose value will be read /// The value of the requested property or nothing if it didn't exist protected: NUCLEX_SUPPORT_API std::optional RetrieveUInt64Property( const std::string &categoryName, const std::string &propertyName ) const override; /// Retrieves the value of a 64 bit integer property from the store /// Category from which the property will be read /// Name of the property whose value will be read /// The value of the requested property or nothing if it didn't exist protected: NUCLEX_SUPPORT_API std::optional RetrieveInt64Property( const std::string &categoryName, const std::string &propertyName ) const override; /// Retrieves the value of a string property from the store /// Category from which the property will be read /// Name of the property whose value will be read /// The value of the requested property or nothing if it didn't exist protected: NUCLEX_SUPPORT_API std::optional RetrieveStringProperty( const std::string &categoryName, const std::string &propertyName ) const override; /// Stores or updates a boolean property in the settings store /// Category from which the property will be read /// Name of the property whose value will be read /// Value that will be stored protected: NUCLEX_SUPPORT_API void StoreBooleanProperty( const std::string &categoryName, const std::string &propertyName, bool value ) override; /// Stores or updates a 32 bit integer property in the settings store /// Category from which the property will be read /// Name of the property whose value will be read /// Value that will be stored protected: NUCLEX_SUPPORT_API void StoreUInt32Property( const std::string &categoryName, const std::string &propertyName, std::uint32_t value ) override; /// Stores or updates a 32 bit integer property in the settings store /// Category from which the property will be read /// Name of the property whose value will be read /// Value that will be stored protected: NUCLEX_SUPPORT_API void StoreInt32Property( const std::string &categoryName, const std::string &propertyName, std::int32_t value ) override; /// Stores or updates a 64 bit integer property in the settings store /// Category from which the property will be read /// Name of the property whose value will be read /// Value that will be stored protected: NUCLEX_SUPPORT_API void StoreUInt64Property( const std::string &categoryName, const std::string &propertyName, std::uint64_t value ) override; /// Stores or updates a 64 bit integer property in the settings store /// Category from which the property will be read /// Name of the property whose value will be read /// Value that will be stored protected: NUCLEX_SUPPORT_API void StoreInt64Property( const std::string &categoryName, const std::string &propertyName, std::int64_t value ) override; /// Stores or updates a string property in the settings store /// Category from which the property will be read /// Name of the property whose value will be read /// Value that will be stored protected: NUCLEX_SUPPORT_API void StoreStringProperty( const std::string &categoryName, const std::string &propertyName, const std::string &value ) override; /// Container for the properties in a category private: typedef std::unordered_map PropertyMap; /// Container for the categories in the settings store private: typedef std::unordered_map CategoryMap; /// All categories stored in this settings store private: CategoryMap categories; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Support::Settings #endif // NUCLEX_SUPPORT_SETTINGS_MEMORYSETTINGSSTORE_H