[DEV] add get api

This commit is contained in:
Edouard DUPIN 2013-08-01 22:33:02 +02:00
parent 9a05682468
commit 2627da57d8
5 changed files with 82 additions and 9 deletions

View File

@ -181,5 +181,34 @@ bool ejson::Object::IGenerate(etk::UString& _data, int32_t _indent) const
} }
ejson::Value* ejson::Object::GetSub(const etk::UString& _named) const
{
return m_value[_named];
}
ejson::Object* ejson::Object::GetSubObject(const etk::UString& _named) const
{
ejson::Value* tmp = m_value[_named];
if (NULL == tmp) {
return NULL;
}
return tmp->ToObject();
}
ejson::String* ejson::Object::GetSubString(const etk::UString& _named) const
{
ejson::Value* tmp = m_value[_named];
if (NULL == tmp) {
return NULL;
}
return tmp->ToString();
}
ejson::Array* ejson::Object::GetSubArray(const etk::UString& _named) const
{
ejson::Value* tmp = m_value[_named];
if (NULL == tmp) {
return NULL;
}
return tmp->ToArray();
}

View File

@ -48,7 +48,10 @@ namespace ejson
protected: protected:
etk::Hash<ejson::Value*> m_value; //!< value of the node (for element this is the name, for text it is the inside text ...) etk::Hash<ejson::Value*> m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
public: public:
ejson::Value* GetSub(const etk::UString& _named) const;
ejson::Object* GetSubObject(const etk::UString& _named) const;
ejson::String* GetSubString(const etk::UString& _named) const;
ejson::Array* GetSubArray(const etk::UString& _named) const;
public: public:
/** /**
* @brief Get the node type. * @brief Get the node type.

View File

@ -31,12 +31,7 @@ bool ejson::String::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
DrawElementParsed(_data[iii], _filePos); DrawElementParsed(_data[iii], _filePos);
#endif #endif
ejson::filePos tmpPos; ejson::filePos tmpPos;
if( _data[iii]==' ' if(m_quoted==true) {
|| _data[iii]=='\t'
|| _data[iii]=='\n'
|| _data[iii]=='\r') {
// white space ==> nothing to do ...
} else if(m_quoted==true) {
// TODO : manage \x // TODO : manage \x
if( _data[iii]!= '\"') { if( _data[iii]!= '\"') {
m_value += _data[iii]; m_value += _data[iii];

View File

@ -130,7 +130,7 @@ void ejson::Document::Display(void)
JSON_INFO("Generated JSON : \n" << tmpp); JSON_INFO("Generated JSON : \n" << tmpp);
} }
etk::UString CreatePosPointer(const etk::UString& _line, int32_t _pos) static etk::UString CreatePosPointer(const etk::UString& _line, int32_t _pos)
{ {
etk::UString out; etk::UString out;
int32_t iii; int32_t iii;
@ -244,3 +244,43 @@ bool ejson::Document::IParse(const etk::UString& _data, int32_t& _pos, ejson::fi
} }
return true; return true;
} }
ejson::Value* ejson::Document::GetSub(const etk::UString& _named) const
{
if (m_subElement == NULL) {
return NULL;
}
ejson::Object* tmp = m_subElement->ToObject();
if (NULL==tmp) {
return NULL;
}
return tmp->GetSub(_named);
}
ejson::Object* ejson::Document::GetSubObject(const etk::UString& _named) const
{
ejson::Value* tmp = GetSub(_named);
if (NULL == tmp) {
return NULL;
}
return tmp->ToObject();
}
ejson::String* ejson::Document::GetSubString(const etk::UString& _named) const
{
ejson::Value* tmp = GetSub(_named);
if (NULL == tmp) {
return NULL;
}
return tmp->ToString();
}
ejson::Array* ejson::Document::GetSubArray(const etk::UString& _named) const
{
ejson::Value* tmp = GetSub(_named);
if (NULL == tmp) {
return NULL;
}
return tmp->ToArray();
}

View File

@ -13,6 +13,9 @@
#include <etk/unicode.h> #include <etk/unicode.h>
#include <etk/Vector.h> #include <etk/Vector.h>
#include <etk/UString.h> #include <etk/UString.h>
#include <ejson/String.h>
#include <ejson/Array.h>
#include <ejson/Object.h>
namespace ejson namespace ejson
{ {
@ -63,7 +66,10 @@ namespace ejson
private: private:
ejson::Value* m_subElement; //!< only element that contain the json document: ejson::Value* m_subElement; //!< only element that contain the json document:
public: public:
// TODO : sdfsdfsdf ejson::Value* GetSub(const etk::UString& _named) const;
ejson::Object* GetSubObject(const etk::UString& _named) const;
ejson::String* GetSubString(const etk::UString& _named) const;
ejson::Array* GetSubArray(const etk::UString& _named) const;
private: private:
bool m_writeErrorWhenDetexted; bool m_writeErrorWhenDetexted;
etk::UString m_comment; etk::UString m_comment;