![]() |
AlexaClientSDK
3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
|
#include <ConfigurationNode.h>
Public Member Functions | |
ConfigurationNode () | |
bool | getBool (const std::string &key, bool *out=nullptr, bool defaultValue=false) const |
bool | getInt (const std::string &key, int *out=nullptr, int defaultValue=0) const |
bool | getUint32 (const std::string &key, uint32_t *out=nullptr, uint32_t defaultValue=0) const |
bool | getString (const std::string &key, std::string *out=nullptr, std::string defaultValue="") const |
bool | getStringValues (const std::string &key, std::set< std::string > *out=nullptr) const |
template<typename InputType , typename OutputType , typename DefaultType > | |
bool | getDuration (const std::string &key, OutputType *out=static_cast< std::chrono::seconds >(0), DefaultType defaultValue=std::chrono::seconds(0)) const |
ConfigurationNode | operator[] (const std::string &key) const |
ConfigurationNode | getChildNode (const char *key) const |
operator bool () const | |
template<typename Type > | |
bool | getValue (const std::string &key, Type *out, Type defaultValue, bool(rapidjson::Value::*isType)() const, Type(rapidjson::Value::*getType)() const) const |
std::string | serialize () const |
ConfigurationNode | getArray (const std::string &key) const |
std::size_t | getArraySize () const |
ConfigurationNode | operator[] (const std::size_t index) const |
Static Public Member Functions | |
static bool | initialize (const std::vector< std::shared_ptr< std::istream >> &jsonStreams) |
static void | uninitialize () |
static std::shared_ptr< ConfigurationNode > | createRoot () |
static ConfigurationNode | getRoot () |
Class providing access to a global read-only configuration object. This object is a tree structure comprised of ConfigurationNode
instances that contain key-value pairs (including ConfigurationNode
values).
Methods to fetch a named value from a ConfigurationNode
are of the form:
This signature allows for fetching a value without the risk of an assertion or exception if the value is not present. It also allows for checking if a key is present, or combining the check and fetch operations in a single call.
Sub ConfigurationNodes
are accessed via operator[], where the index is the name of the sub ConfigurationNode
. If a key for a ConfigurationNode
does not exist an empty ConfigurationNode
is returned instead. This allows for simple and safe traversal of the configuration hierarchy. For example:
The configuration is specified via JSON documents with a root object that corresponds to the root ConfigurationNode
value returned by ConfigurationNode::getRoot(). ConfiguriatonNode Sub-nodes accessed by operator[<key>] correspond to JSON objects values with the of the name <key>. So, the code example above would return "someStringValue" if the configuration was initialized with the following JSON document:
alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::ConfigurationNode | ( | ) |
Constructor.
|
static |
Create a shared_ptr to the root configuration node.
ConfigurationNode alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getArray | ( | const std::string & | key | ) | const |
Get the ConfigurationNode
value that contains an array with key
from this ConfigurationNode
.
key | The key of the ConfigurationNode value to get. |
ConfigurationNode
value, or an empty node if this ConfigurationNode
does not have a ConfigurationNode
value for key
that contains an array. std::size_t alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getArraySize | ( | ) | const |
Get the size of the array from this ConfigurationNode
.
ConfigurationNode
is not an array. Else return the size of the array. bool alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getBool | ( | const std::string & | key, |
bool * | out = nullptr , |
||
bool | defaultValue = false |
||
) | const |
Get bool
value for key
from this ConfigurationNode
.
key | The key of the bool value to get. | |
[out] | out | Pointer to receive the returned value. |
defaultValue | Default value to use if this ConfigurationNode does not have a bool value for key . false if not specified. |
ConfigurationNode
has a bool
value for key
. ConfigurationNode alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getChildNode | ( | const char * | key | ) | const |
Get ConfigurationNode
value for key
from this ConfigurationNode
.
key | The key of the ConfigurationNode value to get. |
ConfigurationNode
value, or an empty node if this ConfigurationNode
does not have a ConfigurationNode
value for key
. bool alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getDuration | ( | const std::string & | key, |
OutputType * | out = static_cast<std::chrono::seconds>(0) , |
||
DefaultType | defaultValue = std::chrono::seconds(0) |
||
) | const |
Get a duration value derived from an integer value for key
from this ConfigurationNode
.
InputType | std::chrono::duration type whose unit specifies how the integer value in the JSON input stream is to be interpreted. |
OutputType | std::chrono::duration type specifying the type of the out parameter to this method. |
DefaultType | std::chrono::duration type specifying the type of the defaultValue to this method. |
key | The key of of the integer value to fetch and convert to OutputType . |
out | Pointer to receive the returned value. |
defaultValue | Default value to use if this ConfigurationNode does not have an integer value value for key . Zero if not specified. |
ConfigurationNode
has an integer value for key
. bool alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getInt | ( | const std::string & | key, |
int * | out = nullptr , |
||
int | defaultValue = 0 |
||
) | const |
Get int
value for key
from this ConfigurationNode
.
key | The key of the int value to get. | |
[out] | out | Pointer to receive the returned value. |
defaultValue | Default value to use if this ConfigurationNode does not have an int value for key . Zero if not specified. |
ConfigurationNode
has an int
value for key
.
|
static |
Get the root ConfigurationNode
of the global configuration.
ConfigurationNode
of the global configuration. bool alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getString | ( | const std::string & | key, |
std::string * | out = nullptr , |
||
std::string | defaultValue = "" |
||
) | const |
Get the string
value for key
from this ConfigurationNode
.
key | The key of the string value to get. | |
[out] | out | Pointer to receive the returned value. |
defaultValue | Default value to use if this ConfigurationNode does not have a string value for key . The empty string if not specified. |
ConfigurationNode
has a string
value for key
. bool alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getStringValues | ( | const std::string & | key, |
std::set< std::string > * | out = nullptr |
||
) | const |
Get the string
value for key
from this ConfigurationNode
.
key | The key of the string value to get. | |
[out] | out | Pointer to receive the returned value. |
ConfigurationNode
has a string
array value for key
. bool alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getUint32 | ( | const std::string & | key, |
uint32_t * | out = nullptr , |
||
uint32_t | defaultValue = 0 |
||
) | const |
Get uint32_t
value for key
from this ConfigurationNode
.
key | The key of the uint32_t value to get. | |
[out] | out | Pointer to receive the returned value. |
defaultValue | Default value to use if this ConfigurationNode does not have an uint32_t value for key . Zero if not specified. |
ConfigurationNode
has an uint32_t
value for key
. bool alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getValue | ( | const std::string & | key, |
Type * | out, | ||
Type | defaultValue, | ||
bool(rapidjson::Value::*)() const | isType, | ||
Type(rapidjson::Value::*)() const | getType | ||
) | const |
Common logic for getting a value of a specific type.
Type | The type to be gotten. |
key | The key of the value to get. |
out | Pointer to receive the value. May be nullptr to just test for the presence of the value. |
defaultValue | A default output value if no value of the desired type for key is present. |
isType | rapidjson::Value member function to test for the desired type. |
getType | rapidjson::Value member function to get the desired type. |
Type
is present for key
.
|
static |
Initialize the global configuration.
initialize()
has already been called since startup or the latest call to uninitialize(), this function will reject the request and return false
.jsonStreams | Vector of istreams containing JSON documents from which to parse configuration parameters. Streams are processed in the order they appear in the vector. When a value appears in more than one JSON stream the last processed stream's value overwrites the previous value (and a debug log entry will be created). This allows for specifying default settings (by providing them first) and specifying the configuration from multiple sources (e.g. a separate stream for each component). The resulting global configuration may be accessed from getRoot() . |
alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::operator bool | ( | ) | const |
operator bool(). Indicates of the ConfigurationNode
references a valid object.
ConfigurationNode
references a valid object. ConfigurationNode alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::operator[] | ( | const std::string & | key | ) | const |
operator[] to get ConfigurationNode
value for key
from this ConfigurationNode
.
key | The key of the ConfigurationNode value to get. |
ConfigurationNode
value, or an empty node if this ConfigurationNode
does not have a ConfigurationNode
value for key
. ConfigurationNode alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::operator[] | ( | const std::size_t | index | ) | const |
operator[] to get ConfigurationNode
value from an array from index
of this ConfigurationNode
.
index | The index of the array of the ConfigurationNode to get. |
ConfigurationNode
value, or an empty node if this ConfigurationNode
is not an array or the the index is out of range. std::string alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::serialize | ( | ) | const |
Serialize the object into a string
|
static |
Uninitialize the global configuration.
AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0