[DEV] add value getter on Array

This commit is contained in:
Edouard DUPIN 2013-08-24 22:00:32 +02:00
parent cc4cdca147
commit 299ca3e6b2
2 changed files with 59 additions and 7 deletions

View File

@ -314,3 +314,41 @@ ejson::Boolean* ejson::Array::GetBoolean(esize_t _id)
return tmpElement->ToBoolean();
}
const etk::UString& ejson::Array::GetStringValue(esize_t _id)
{
static const etk::UString errorValue("");
ejson::String* tmpElement = GetString(_id);
if (NULL == tmpElement) {
return errorValue;
}
return tmpElement->Get();
}
etk::UString ejson::Array::GetStringValue(esize_t _id, const etk::UString& _errorValue)
{
ejson::String* tmpElement = GetString(_id);
if (NULL == tmpElement) {
return _errorValue;
}
return tmpElement->Get();
}
double ejson::Array::GetNumberValue(esize_t _id, double _errorValue)
{
ejson::Number* tmpElement = GetNumber(_id);
if (NULL == tmpElement) {
return _errorValue;
}
return tmpElement->Get();
}
bool ejson::Array::GetBooleanValue(esize_t _id, bool _errorValue)
{
ejson::Boolean* tmpElement = GetBoolean(_id);
if (NULL == tmpElement) {
return _errorValue;
}
return tmpElement->Get();
}

View File

@ -34,12 +34,13 @@ namespace ejson
* @brief Get the number of sub element in the current one
* @return the Number of stored element
*/
esize_t Size(void) { return m_value.Size(); };
esize_t Size(void) const { return m_value.Size(); };
/**
* @brief Get the pointer on an element reference with his ID.
* @param[in] _id Id of the element.
* @return NULL if the element does not exist.
*/
const ejson::Value* Get(esize_t _id) const { return m_value[_id]; };
ejson::Value* Get(esize_t _id) { return m_value[_id]; };
/**
* @brief Get the pointer on an element reference with his ID (casted in Object if it is an object).
@ -54,15 +55,16 @@ namespace ejson
*/
ejson::String* GetString(esize_t _id);
/**
* @brief Get the value of the string element (if not a strin return "")
* @brief Get the value of the string element (if not a string return "")
* @param[in] _id Id of the element.
* @return value of the element
* @return value of the element.
*/
const etk::UString& GetStringValue(esize_t _id);
/**
* @brief Get the value of the string element (if not a strin return "")
* @brief Get the value of the string element
* @param[in] _id Id of the element.
* @return value of the element
* @param[in] _errorValue The return value if an error occured.
* @return value of the element, or the _errorValue.
*/
etk::UString GetStringValue(esize_t _id, const etk::UString& _errorValue);
/**
@ -83,14 +85,26 @@ namespace ejson
* @return NULL if the element does not exist.
*/
ejson::Number* GetNumber(esize_t _id);
/**
* @brief Get the value of the Number element
* @param[in] _id Id of the element.
* @param[in] _errorValue The return value if an error occured.
* @return value of the element, or the _errorValue.
*/
double GetNumberValue(esize_t _id, double _errorValue);
/**
* @brief Get the pointer on an element reference with his ID (casted in Boolean if it is an Boolean).
* @param[in] _id Id of the element.
* @return NULL if the element does not exist.
*/
ejson::Boolean* GetBoolean(esize_t _id);
/**
* @brief Get the value of the Boolean element
* @param[in] _id Id of the element.
* @param[in] _errorValue The return value if an error occured.
* @return value of the element, or the _errorValue.
*/
bool GetBooleanValue(esize_t _id, bool _errorValue);
/**
* @brief Add an element on the array.
* @param[in] _element element to add.