[DEV] add some capabilities

This commit is contained in:
Edouard DUPIN 2013-06-24 21:19:44 +02:00
parent 8543095cf3
commit ce8bef3599
3 changed files with 37 additions and 0 deletions

View File

@ -18,6 +18,7 @@ namespace exml
{ {
public: public:
Declaration(void) { }; Declaration(void) { };
Declaration(const etk::UString& _version, const etk::UString& _format, const etk::UString& _validation) { };
virtual ~Declaration(void) { }; virtual ~Declaration(void) { };
virtual nodeType_te GetType(void) const { return typeAttribute; }; virtual nodeType_te GetType(void) const { return typeAttribute; };
virtual bool Generate(etk::UString& _data, int32_t _indent) const; virtual bool Generate(etk::UString& _data, int32_t _indent) const;

View File

@ -81,6 +81,7 @@ exml::Attribute* exml::Element::GetAttr(int32_t _id)
} }
return m_listAttribute[_id]; return m_listAttribute[_id];
} }
const exml::Attribute* exml::Element::GetAttr(int32_t _id) const const exml::Attribute* exml::Element::GetAttr(int32_t _id) const
{ {
if (_id <0 || _id>m_listAttribute.Size()) { if (_id <0 || _id>m_listAttribute.Size()) {
@ -88,6 +89,7 @@ const exml::Attribute* exml::Element::GetAttr(int32_t _id) const
} }
return m_listAttribute[_id]; return m_listAttribute[_id];
} }
void exml::Element::AppendAttribute(exml::Attribute* _node) void exml::Element::AppendAttribute(exml::Attribute* _node)
{ {
if (_node == NULL) { if (_node == NULL) {
@ -118,6 +120,37 @@ const etk::UString& exml::Element::GetAttribute(const etk::UString& _name) const
return errorReturn; return errorReturn;
} }
void exml::Element::SetAttribute(const etk::UString& _name, const etk::UString& _value)
{
// check if attribute already det :
for (int32_t iii=0; iii<m_listAttribute.Size(); iii++) {
if( NULL != m_listAttribute[iii]
&& m_listAttribute[iii]->GetName() == _name) {
// update the value :
m_listAttribute[iii]->SetValue(_value);
return;
}
}
exml::Attribute* attr = new exml::Attribute(_name, _value);
if (NULL==attr) {
EXML_ERROR("memory allocation error...");
}
m_listAttribute.PushBack(attr);
}
etk::UString exml::Element::GetText(void)
{
// TODO : Add more capabilities ...
etk::UString res;
for (int32_t iii=0; iii<m_listSub.Size(); iii++) {
if (NULL!=m_listSub[iii]) {
m_listSub[iii]->Generate(res, 0);
}
}
return res;
}
bool exml::Element::Generate(etk::UString& _data, int32_t _indent) const bool exml::Element::Generate(etk::UString& _data, int32_t _indent) const
{ {
AddIndent(_data, _indent); AddIndent(_data, _indent);

View File

@ -39,6 +39,9 @@ namespace exml
Attribute* GetAttr(int32_t _id); Attribute* GetAttr(int32_t _id);
const Attribute* GetAttr(int32_t _id) const; const Attribute* GetAttr(int32_t _id) const;
const etk::UString& GetAttribute(const etk::UString& _name) const; const etk::UString& GetAttribute(const etk::UString& _name) const;
void SetAttribute(const etk::UString& _name, const etk::UString& _value);
public:
etk::UString GetText(void);
public: public:
virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos); virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos);
virtual bool Generate(etk::UString& _data, int32_t _indent) const; virtual bool Generate(etk::UString& _data, int32_t _indent) const;