Fledge
An open source edge computing platform for industrial users
ConfigCategory Class Reference
Inheritance diagram for ConfigCategory:

Classes

class  CategoryItem
 

Public Types

enum  ItemType {
  UnknownType, StringItem, EnumerationItem, JsonItem,
  BoolItem, NumberItem, DoubleItem, ScriptItem,
  CategoryType, CodeItem, BucketItem, ListItem,
  KVListItem
}
 
enum  ItemAttribute {
  ORDER_ATTR, READONLY_ATTR, MANDATORY_ATTR, FILE_ATTR,
  MINIMUM_ATTR, MAXIMUM_ATTR, LENGTH_ATTR, VALIDITY_ATTR,
  GROUP_ATTR, DISPLAY_NAME_ATTR, DEPRECATED_ATTR, RULE_ATTR,
  BUCKET_PROPERTIES_ATTR, LIST_SIZE_ATTR, ITEM_TYPE_ATTR, LIST_NAME_ATTR,
  KVLIST_KEY_NAME_ATTR, KVLIST_KEY_DESCRIPTION_ATTR, JSON_SCHEMA_ATTR
}
 
using iterator = std::vector< CategoryItem * >::iterator
 
using const_iterator = std::vector< CategoryItem * >::const_iterator
 

Public Member Functions

 ConfigCategory (const std::string &name, const std::string &json)
 
 ConfigCategory (const ConfigCategory &orig)
 Copy constructor for a configuration category. More...
 
 ConfigCategory (const ConfigCategory *orig)
 Copy constructor for a configuration category when copying from a pointer. More...
 
 ~ConfigCategory ()
 Configuration category destructor.
 
void addItem (const std::string &name, const std::string description, const std::string &type, const std::string def, const std::string &value)
 Add an item to a configuration category.
 
void addItem (const std::string &name, const std::string description, const std::string def, const std::string &value, const std::vector< std::string > options)
 
void removeItems ()
 Delete all the items from the configuration category. More...
 
void removeItemsType (ItemType type)
 Delete all the items from the configuration category having a specific type. More...
 
void keepItemsType (ItemType type)
 Delete all the items from the configuration category not having a specific type. More...
 
bool extractSubcategory (ConfigCategory &subCategories)
 Extracts, process and adds subcategory information from a given category to the current instance. More...
 
void setDescription (const std::string &description)
 Set the description for the configuration category. More...
 
std::string getName () const
 
std::string getDescription () const
 
std::string getDisplayName () const
 
void setDisplayName (const std::string &displayName)
 
unsigned int getCount () const
 
bool itemExists (const std::string &name) const
 Check for the existence of an item within the configuration category. More...
 
bool setItemDisplayName (const std::string &name, const std::string &displayName)
 Set the display name of an item. More...
 
std::string getValue (const std::string &name) const
 Return the value of the configuration category item. More...
 
std::vector< std::string > getValueList (const std::string &name) const
 Return the value of the configuration category item list, this is a convience function used when simple lists are defined and allows for central processing of the list values. More...
 
std::map< std::string, std::string > getValueKVList (const std::string &name) const
 Return the value of the configuration category item kvlist, this is a convience function used when key/value lists are defined and allows for central processing of the list values. More...
 
std::string getType (const std::string &name) const
 Return the type of the configuration category item. More...
 
std::string getDescription (const std::string &name) const
 
std::string getDefault (const std::string &name) const
 Return the default value of the configuration category item. More...
 
bool setDefault (const std::string &name, const std::string &value)
 Update the default value of the configuration category item. More...
 
bool setValue (const std::string &name, const std::string &value)
 Update the value of the configuration category item. More...
 
std::string getDisplayName (const std::string &name) const
 
std::string getmParentName () const
 
std::vector< std::string > getOptions (const std::string &name) const
 Return the options of the configuration category item. More...
 
std::string getLength (const std::string &name) const
 Return the length value of the configuration category item. More...
 
std::string getMinimum (const std::string &name) const
 Return the minimum value of the configuration category item. More...
 
std::string getMaximum (const std::string &name) const
 Return the maximum of the configuration category item. More...
 
bool isString (const std::string &name) const
 Return if the configuration item is a string item. More...
 
bool isEnumeration (const std::string &name) const
 Return if the configuration item is an enumeration item. More...
 
bool isJSON (const std::string &name) const
 Return if the configuration item is a JSON item. More...
 
bool isBool (const std::string &name) const
 Return if the configuration item is a Bool item. More...
 
bool isNumber (const std::string &name) const
 Return if the configuration item is a Numeric item. More...
 
bool isDouble (const std::string &name) const
 Return if the configuration item is a Double item. More...
 
bool isList (const std::string &name) const
 Return if the configuration item is a list item. More...
 
bool isKVList (const std::string &name) const
 Return if the configuration item is a kvlist item. More...
 
bool isDeprecated (const std::string &name) const
 Return if the configuration item is deprecated a item. More...
 
std::string toJSON (const bool full=false) const
 Return JSON string of all category components. More...
 
std::string itemsToJSON (const bool full=false) const
 Return JSON string of category items only. More...
 
ConfigCategoryoperator= (ConfigCategory const &rhs)
 Operator= for ConfigCategory.
 
ConfigCategoryoperator+= (ConfigCategory const &rhs)
 Operator+= for ConfigCategory.
 
void setItemsValueFromDefault ()
 Set the m_value from m_default for each item.
 
void checkDefaultValuesOnly () const
 Check whether at least one item in the category object has both 'value' and 'default' set. More...
 
std::string itemToJSON (const std::string &itemName) const
 Return JSON string of a category item. More...
 
std::string to_string (const rapidjson::Value &v) const
 Convert a RapidJSON value to a string. More...
 
std::vector< std::string > getPermissions (const std::string &name) const
 Return the permissions of the configuration category item. More...
 
bool hasPermission (const std::string &name, const std::string &username) const
 Return true if the user has permission to update the named item. More...
 
std::string getItemAttribute (const std::string &itemName, ItemAttribute itemAttribute) const
 Return the requested attribute of a configuration category item. More...
 
bool setItemAttribute (const std::string &itemName, ItemAttribute itemAttribute, const std::string &value)
 Set the requested attribute of a configuration category item. More...
 
std::vector< std::pair< std::string, std::string > > * parseBucketItemValue (const std::string &)
 Parse BucketItem value in JSON dict format and return the key value pairs within that. More...
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 

Protected Attributes

std::vector< CategoryItem * > m_items
 
std::string m_name
 
std::string m_parent_name
 
std::string m_description
 
std::string m_displayName
 

Constructor & Destructor Documentation

◆ ConfigCategory() [1/2]

ConfigCategory::ConfigCategory ( const ConfigCategory orig)

Copy constructor for a configuration category.

Parameters
rhsThe configuration category to copy

◆ ConfigCategory() [2/2]

ConfigCategory::ConfigCategory ( const ConfigCategory orig)

Copy constructor for a configuration category when copying from a pointer.

Parameters
rhsThe configuration category to copy

Member Function Documentation

◆ checkDefaultValuesOnly()

void ConfigCategory::checkDefaultValuesOnly ( ) const

Check whether at least one item in the category object has both 'value' and 'default' set.

Exceptions
ConfigValueFoundWithDefault

◆ extractSubcategory()

bool ConfigCategory::extractSubcategory ( ConfigCategory subCategories)

Extracts, process and adds subcategory information from a given category to the current instance.

  • Parameters
    subCategoriesConfiguration category from which the subcategories information should be extracted

◆ getDefault()

string ConfigCategory::getDefault ( const std::string &  name) const

Return the default value of the configuration category item.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ getItemAttribute()

string ConfigCategory::getItemAttribute ( const std::string &  itemName,
ItemAttribute  itemAttribute 
) const

Return the requested attribute of a configuration category item.

Parameters
nameThe name of the configuration item to return
itemAttributeThe item attribute (such as "file", "order", "readonly"
Returns
The configuration item attribute as string
Exceptions
ConfigItemNotFoundif the item does not exist in the category ConfigItemAttributeNotFound if the requested attribute does not exist for the found item.

◆ getLength()

string ConfigCategory::getLength ( const std::string &  name) const

Return the length value of the configuration category item.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ getMaximum()

string ConfigCategory::getMaximum ( const std::string &  name) const

Return the maximum of the configuration category item.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ getMinimum()

string ConfigCategory::getMinimum ( const std::string &  name) const

Return the minimum value of the configuration category item.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ getOptions()

vector< string > ConfigCategory::getOptions ( const std::string &  name) const

Return the options of the configuration category item.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ getPermissions()

vector< string > ConfigCategory::getPermissions ( const std::string &  name) const

Return the permissions of the configuration category item.

Parameters
nameThe name of the configuration item to return
Returns
vector<string> The configuration item permissions
Exceptions
exceptionif the item does not exist in the category

◆ getType()

string ConfigCategory::getType ( const std::string &  name) const

Return the type of the configuration category item.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ getValue()

string ConfigCategory::getValue ( const std::string &  name) const

Return the value of the configuration category item.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ getValueKVList()

map< string, string > ConfigCategory::getValueKVList ( const std::string &  name) const

Return the value of the configuration category item kvlist, this is a convience function used when key/value lists are defined and allows for central processing of the list values.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ getValueList()

vector< string > ConfigCategory::getValueList ( const std::string &  name) const

Return the value of the configuration category item list, this is a convience function used when simple lists are defined and allows for central processing of the list values.

Parameters
nameThe name of the configuration item to return
Returns
string The configuration item name
Exceptions
exceptionif the item does not exist in the category

◆ hasPermission()

bool ConfigCategory::hasPermission ( const std::string &  name,
const std::string &  rolename 
) const

Return true if the user has permission to update the named item.

Parameters
nameThe name of the configuration item to return
rolenameThe name of the user role to test
Returns
bool True if the named user can update the configuration item
Exceptions
exceptionif the item does not exist in the category

◆ isBool()

bool ConfigCategory::isBool ( const std::string &  name) const

Return if the configuration item is a Bool item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a Bool type
Exceptions
exceptionIf the item was not found in the configuration category

◆ isDeprecated()

bool ConfigCategory::isDeprecated ( const std::string &  name) const

Return if the configuration item is deprecated a item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a deprecated type
Exceptions
exceptionIf the item was not found in the configuration category

◆ isDouble()

bool ConfigCategory::isDouble ( const std::string &  name) const

Return if the configuration item is a Double item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a Double type
Exceptions
exceptionIf the item was not found in the configuration category

◆ isEnumeration()

bool ConfigCategory::isEnumeration ( const std::string &  name) const

Return if the configuration item is an enumeration item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a string type
Exceptions
exceptionIf the item was not found in the configuration category

◆ isJSON()

bool ConfigCategory::isJSON ( const std::string &  name) const

Return if the configuration item is a JSON item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a JSON type
Exceptions
exceptionIf the item was not found in the configuration category

◆ isKVList()

bool ConfigCategory::isKVList ( const std::string &  name) const

Return if the configuration item is a kvlist item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a Numeric type
Exceptions
exceptionIf the item was not found in the configuration category

◆ isList()

bool ConfigCategory::isList ( const std::string &  name) const

Return if the configuration item is a list item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a Numeric type
Exceptions
exceptionIf the item was not found in the configuration category

◆ isNumber()

bool ConfigCategory::isNumber ( const std::string &  name) const

Return if the configuration item is a Numeric item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a Numeric type
Exceptions
exceptionIf the item was not found in the configuration category

◆ isString()

bool ConfigCategory::isString ( const std::string &  name) const

Return if the configuration item is a string item.

Parameters
nameThe name of the item to test
Returns
bool True if the item is a string type
Exceptions
exceptionIf the item was not found in the configuration category

◆ itemExists()

bool ConfigCategory::itemExists ( const std::string &  name) const

Check for the existence of an item within the configuration category.

Parameters
nameItem name to check within the category

◆ itemsToJSON()

string ConfigCategory::itemsToJSON ( const bool  full = false) const

Return JSON string of category items only.

Parameters
fullfalse is the deafult, true evaluates all the members of the CategoryItems

◆ itemToJSON()

string ConfigCategory::itemToJSON ( const std::string &  itemName) const

Return JSON string of a category item.

Parameters
itemNameThe given item within current category
Returns
The JSON string version of itemName If not found {} is returned

◆ keepItemsType()

void ConfigCategory::keepItemsType ( ConfigCategory::ItemType  type)

Delete all the items from the configuration category not having a specific type.

  • Parameters
    typeType to maintain

◆ parseBucketItemValue()

vector< pair< string, string > > * ConfigCategory::parseBucketItemValue ( const std::string &  )

Parse BucketItem value in JSON dict format and return the key value pairs within that.

Parameters
jsonJSON string representing the BucketItem value
Returns
Vector with pairs of found key/value string pairs in BucketItem value

◆ removeItems()

void ConfigCategory::removeItems ( )

Delete all the items from the configuration category.

◆ removeItemsType()

void ConfigCategory::removeItemsType ( ConfigCategory::ItemType  type)

Delete all the items from the configuration category having a specific type.

  • Parameters
    typeType to delete

◆ setDefault()

bool ConfigCategory::setDefault ( const std::string &  name,
const std::string &  value 
)

Update the default value of the configuration category item.

Parameters
nameThe name of the configuration item to update
valueNew value of the configuration item
Returns
bool Whether update succeeded

◆ setDescription()

void ConfigCategory::setDescription ( const std::string &  description)

Set the description for the configuration category.

Parameters
descriptionThe configuration category description

◆ setItemAttribute()

bool ConfigCategory::setItemAttribute ( const std::string &  itemName,
ItemAttribute  itemAttribute,
const std::string &  value 
)

Set the requested attribute of a configuration category item.

Parameters
nameThe name of the configuration item to return
itemAttributeThe item attribute (such as "file", "order", "readonly"
valueThe value to set
Returns
The configuration item attribute as string
Exceptions
ConfigItemNotFoundif the item does not exist in the category ConfigItemAttributeNotFound if the requested attribute does not exist for the found item.

◆ setItemDisplayName()

bool ConfigCategory::setItemDisplayName ( const std::string &  name,
const std::string &  displayName 
)

Set the display name of an item.

Parameters
nameThe item name in the category
displayNameThe display name to set
Returns
true if the item was found

◆ setValue()

bool ConfigCategory::setValue ( const std::string &  name,
const std::string &  value 
)

Update the value of the configuration category item.

Parameters
nameThe name of the configuration item to update
valueNew value of the configuration item
Returns
bool Whether update succeeded

◆ to_string()

std::string ConfigCategory::to_string ( const rapidjson::Value &  v) const

Convert a RapidJSON value to a string.

Parameters
vThe RapidJSON value

◆ toJSON()

string ConfigCategory::toJSON ( const bool  full = false) const

Return JSON string of all category components.

Parameters
fullfalse is the deafult, true evaluates all the members of the CategoryItems

The documentation for this class was generated from the following files: