[DEV] codestyle review

This commit is contained in:
Edouard DUPIN 2013-11-10 14:43:25 +01:00
parent 5009e90a1e
commit c9f7abcd96
15 changed files with 298 additions and 217 deletions

View File

@ -14,14 +14,12 @@
#define __class__ "Attribute"
exml::Attribute::Attribute(const etk::UString& _name, const etk::UString& _value) :
exml::Node(_value),
m_name(_name)
{
exml::Node(_value),
m_name(_name) {
}
bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc)
{
bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'attribute'");
m_pos = _filePos;
// search end of the comment :
@ -108,8 +106,7 @@ bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _cas
return true;
}
bool exml::Attribute::iGenerate(etk::UString& _data, int32_t _indent) const
{
bool exml::Attribute::iGenerate(etk::UString& _data, int32_t _indent) const {
_data += " ";
_data += m_name;
_data += "=\"";
@ -118,10 +115,7 @@ bool exml::Attribute::iGenerate(etk::UString& _data, int32_t _indent) const
return true;
}
void exml::Attribute::clear(void)
{
void exml::Attribute::clear(void) {
m_name="";
}

View File

@ -12,10 +12,8 @@
#include <exml/Node.h>
#include <etk/Vector.h>
namespace exml
{
class Attribute : public Node
{
namespace exml {
class Attribute : public Node {
public:
/**
* @brief Constructor
@ -38,18 +36,28 @@ namespace exml
* @brief set the name of the attribute
* @param[in] _name New name of the attribute
*/
virtual void setName(etk::UString _name) { m_name = _name; };
virtual void setName(etk::UString _name) {
m_name = _name;
};
/**
* @brief get the current name of the Attribute
* @return String of the attribute
*/
virtual const etk::UString& getName(void) const { return m_name; };
virtual const etk::UString& getName(void) const {
return m_name;
};
public: // herited function:
virtual nodeType_te getType(void) const { return exml::typeAttribute; };
virtual enum nodeType getType(void) const {
return exml::typeAttribute;
};
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual exml::Attribute* toAttribute(void) { return this; };
virtual const exml::Attribute* toAttribute(void) const { return this; };
virtual exml::Attribute* toAttribute(void) {
return this;
};
virtual const exml::Attribute* toAttribute(void) const {
return this;
};
virtual void clear(void);
};
};

View File

@ -12,8 +12,7 @@
#undef __class__
#define __class__ "AttributeList"
exml::AttributeList::~AttributeList(void)
{
exml::AttributeList::~AttributeList(void) {
for (int32_t iii=0; iii<m_listAttribute.size(); iii++) {
if (NULL!=m_listAttribute[iii]) {
delete(m_listAttribute[iii]);
@ -23,24 +22,21 @@ exml::AttributeList::~AttributeList(void)
m_listAttribute.clear();
}
exml::Attribute* exml::AttributeList::getAttr(int32_t _id)
{
exml::Attribute* exml::AttributeList::getAttr(int32_t _id) {
if (_id <0 || _id>m_listAttribute.size()) {
return NULL;
}
return m_listAttribute[_id];
}
const exml::Attribute* exml::AttributeList::getAttr(int32_t _id) const
{
const exml::Attribute* exml::AttributeList::getAttr(int32_t _id) const {
if (_id <0 || _id>m_listAttribute.size()) {
return NULL;
}
return m_listAttribute[_id];
}
void exml::AttributeList::appendAttribute(exml::Attribute* _attr)
{
void exml::AttributeList::appendAttribute(exml::Attribute* _attr) {
if (_attr == NULL) {
EXML_ERROR("Try to set an empty node");
return;
@ -54,8 +50,7 @@ void exml::AttributeList::appendAttribute(exml::Attribute* _attr)
m_listAttribute.pushBack(_attr);
}
const etk::UString& exml::AttributeList::getAttribute(const etk::UString& _name) const
{
const etk::UString& exml::AttributeList::getAttribute(const etk::UString& _name) const {
static const etk::UString errorReturn("");
if (_name.size() == 0) {
return errorReturn;
@ -69,8 +64,7 @@ const etk::UString& exml::AttributeList::getAttribute(const etk::UString& _name)
return errorReturn;
}
bool exml::AttributeList::existAttribute(const etk::UString& _name) const
{
bool exml::AttributeList::existAttribute(const etk::UString& _name) const {
if (_name.size() == 0) {
return false;
}
@ -83,8 +77,7 @@ bool exml::AttributeList::existAttribute(const etk::UString& _name) const
return false;
}
void exml::AttributeList::setAttribute(const etk::UString& _name, const etk::UString& _value)
{
void exml::AttributeList::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]
@ -101,8 +94,7 @@ void exml::AttributeList::setAttribute(const etk::UString& _name, const etk::USt
m_listAttribute.pushBack(attr);
}
bool exml::AttributeList::iGenerate(etk::UString& _data, int32_t _indent) const
{
bool exml::AttributeList::iGenerate(etk::UString& _data, int32_t _indent) const {
for (int32_t iii=0; iii<m_listAttribute.size(); iii++) {
if (NULL!=m_listAttribute[iii]) {
m_listAttribute[iii]->iGenerate(_data, _indent);
@ -111,8 +103,7 @@ bool exml::AttributeList::iGenerate(etk::UString& _data, int32_t _indent) const
return true;
}
void exml::AttributeList::clear(void)
{
void exml::AttributeList::clear(void) {
exml::Node::clear();
for (int32_t iii=0; iii<m_listAttribute.size(); iii++) {
if (NULL!=m_listAttribute[iii]) {

View File

@ -13,10 +13,8 @@
#include <etk/Vector.h>
#include <exml/Attribute.h>
namespace exml
{
class AttributeList : public Node
{
namespace exml {
class AttributeList : public Node {
public:
/**
* @brief Constructor
@ -26,7 +24,10 @@ namespace exml
* @brief Constructor
* @param[in] _value Node value;
*/
AttributeList(const etk::UString& _value) : exml::Node(_value) { };
AttributeList(const etk::UString& _value) :
exml::Node(_value) {
};
/**
* @brief Destructor
*/
@ -38,7 +39,9 @@ namespace exml
* @brief get the number of attribute in the Node
* @return Nulber of attribute >=0
*/
int32_t sizeAttribute(void) const { return m_listAttribute.size(); };
int32_t sizeAttribute(void) const {
return m_listAttribute.size();
};
/**
* @brief add attribute on the List
* @param[in] _attr Pointer on the attribute

View File

@ -13,8 +13,7 @@
#undef __class__
#define __class__ "Comment"
bool exml::Comment::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc)
{
bool exml::Comment::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'comment'");
m_pos = _filePos;
exml::filePos tmpPos;
@ -53,8 +52,7 @@ bool exml::Comment::iParse(const etk::UString& _data, int32_t& _pos, bool _caseS
return false;
}
bool exml::Comment::iGenerate(etk::UString& _data, int32_t _indent) const
{
bool exml::Comment::iGenerate(etk::UString& _data, int32_t _indent) const {
addIndent(_data, _indent);
_data += "<!--";
_data += m_value;

View File

@ -12,10 +12,8 @@
#include <exml/Node.h>
#include <etk/Vector.h>
namespace exml
{
class Comment : public Node
{
namespace exml {
class Comment : public Node {
public:
/**
* @brief Constructor
@ -25,17 +23,26 @@ namespace exml
* @brief Constructor
* @param[in] _value comment value
*/
Comment(const etk::UString& _value) : exml::Node(_value) { };
Comment(const etk::UString& _value) :
exml::Node(_value) {
};
/**
* @brief Destructor
*/
virtual ~Comment(void) { };
public: // herited function:
virtual nodeType_te getType(void) const { return typeAttribute; };
virtual enum nodeType getType(void) const {
return typeAttribute;
};
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual exml::Comment* toComment(void) { return this; };
virtual const exml::Comment* toComment(void) const { return this; };
virtual exml::Comment* toComment(void) {
return this;
};
virtual const exml::Comment* toComment(void) const {
return this;
};
};
};

View File

@ -20,13 +20,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
*/
exml::DeclarationXML::DeclarationXML(const etk::UString& _version, unicode::charset_te _format, bool _standalone) :
exml::Declaration("xml")
{
exml::DeclarationXML::DeclarationXML(const etk::UString& _version, enum unicode::charset _format, bool _standalone) :
exml::Declaration("xml") {
if (_version.size()!=0) {
setAttribute("version", _version);
}
if (_format!=unicode::EDN_CHARSET_UTF8) {
if (_format!=unicode::charsetUTF8) {
setAttribute("encoding", "UTF-8");
} else {
EXML_ERROR("Actually does not supported other charset than UTF8");
@ -39,8 +38,7 @@ exml::DeclarationXML::DeclarationXML(const etk::UString& _version, unicode::char
}
}
bool exml::Declaration::iGenerate(etk::UString& _data, int32_t _indent) const
{
bool exml::Declaration::iGenerate(etk::UString& _data, int32_t _indent) const {
addIndent(_data, _indent);
_data += "<?";
_data += m_value;
@ -49,8 +47,7 @@ bool exml::Declaration::iGenerate(etk::UString& _data, int32_t _indent) const
return true;
}
bool exml::Declaration::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc)
{
bool exml::Declaration::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'declaration' : '" << m_value << "'");
m_pos = _filePos;
// search end of the comment :

View File

@ -11,10 +11,8 @@
#include <exml/AttributeList.h>
namespace exml
{
class Declaration : public exml::AttributeList
{
namespace exml {
class Declaration : public exml::AttributeList {
public:
/**
* @brief Constructor
@ -24,20 +22,28 @@ namespace exml
* @brief Constructor
* @param[in] _name name of the declaration (xml, xml:xxxx ...)
*/
Declaration(const etk::UString& _name) : exml::AttributeList(_name) { };
Declaration(const etk::UString& _name) :
exml::AttributeList(_name) {
};
/**
* @brief Destructor
*/
virtual ~Declaration(void) { };
public: // herited function:
virtual nodeType_te getType(void) const { return typeAttribute; };
virtual enum nodeType getType(void) const {
return typeAttribute;
};
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual exml::Declaration* toDeclaration(void) { return this; };
virtual const exml::Declaration* toDeclaration(void) const { return this; };
virtual exml::Declaration* toDeclaration(void) {
return this;
};
virtual const exml::Declaration* toDeclaration(void) const {
return this;
};
};
class DeclarationXML : public exml::Declaration
{
class DeclarationXML : public exml::Declaration {
public:
/**
* @brief Constructor for the generic declaration : <?xml version="" format="UTF-8"?>
@ -45,7 +51,7 @@ namespace exml
* @param[in] _format charset of the XML
* @param[in] _standalone this document is standalone
*/
DeclarationXML(const etk::UString& _version, unicode::charset_te _format=unicode::EDN_CHARSET_UTF8, bool _standalone=true);
DeclarationXML(const etk::UString& _version, enum unicode::charset _format=unicode::charsetUTF8, bool _standalone=true);
/**
* @brief Destructor
*/

View File

@ -13,20 +13,18 @@
#undef __class__
#define __class__ "Document"
exml::Document::Document(void) :
m_charset(unicode::EDN_CHARSET_UTF8),
m_caseSensitive(false),
m_writeErrorWhenDetexted(true),
m_comment(""),
m_Line(""),
m_filePos(0,0)
{
exml::Document::Document(void) :
m_charset(unicode::charsetUTF8),
m_caseSensitive(false),
m_writeErrorWhenDetexted(true),
m_comment(""),
m_Line(""),
m_filePos(0,0) {
}
bool exml::Document::iGenerate(etk::UString& _data, int32_t _indent) const
{
bool exml::Document::iGenerate(etk::UString& _data, int32_t _indent) const {
for (int32_t iii=0; iii<m_listSub.size(); iii++) {
if (NULL!=m_listSub[iii]) {
m_listSub[iii]->iGenerate(_data, _indent);
@ -35,26 +33,23 @@ bool exml::Document::iGenerate(etk::UString& _data, int32_t _indent) const
return true;
}
bool exml::Document::parse(const etk::UString& _data)
{
bool exml::Document::parse(const etk::UString& _data) {
EXML_VERBOSE("Start parsing document (type: string) size=" << _data.size());
clear();
// came from char == > force in utf8 ...
m_charset = unicode::EDN_CHARSET_UTF8;
m_charset = unicode::charsetUTF8;
exml::filePos filePos(1,0);
m_pos = filePos;
int32_t parsePos = 0;
return subParse(_data, parsePos, m_caseSensitive, filePos, *this, true);
}
bool exml::Document::generate(etk::UString& _data)
{
bool exml::Document::generate(etk::UString& _data) {
_data = "";
return iGenerate(_data,0);
}
bool exml::Document::load(const etk::UString& _file)
{
bool exml::Document::load(const etk::UString& _file) {
// Start loading the XML :
EXML_VERBOSE("open file (xml) \"" << _file << "\"");
clear();
@ -86,7 +81,7 @@ bool exml::Document::load(const etk::UString& _file)
tmpFile.fileClose();
// convert in UTF8 :
etk::UString tmpDataUnicode(fileBuffer, unicode::EDN_CHARSET_UTF8);
etk::UString tmpDataUnicode(fileBuffer, unicode::charsetUTF8);
// remove temporary buffer:
delete(fileBuffer);
// parse the data :
@ -95,8 +90,7 @@ bool exml::Document::load(const etk::UString& _file)
return ret;
}
bool exml::Document::store(const etk::UString& _file)
{
bool exml::Document::store(const etk::UString& _file) {
etk::UString createData;
if (false == generate(createData)) {
EXML_ERROR("Error while creating the XML : " << _file);
@ -117,15 +111,13 @@ bool exml::Document::store(const etk::UString& _file)
return true;
}
void exml::Document::display(void)
{
void exml::Document::display(void) {
etk::UString tmpp;
iGenerate(tmpp, 0);
EXML_INFO("Generated XML : \n" << tmpp);
}
etk::UString createPosPointer(const etk::UString& _line, int32_t _pos)
{
etk::UString createPosPointer(const etk::UString& _line, int32_t _pos) {
etk::UString out;
int32_t iii;
for (iii=0; iii<_pos && iii<_line.size(); iii++) {
@ -142,8 +134,7 @@ etk::UString createPosPointer(const etk::UString& _line, int32_t _pos)
return out;
}
void exml::Document::displayError(void)
{
void exml::Document::displayError(void) {
if (m_comment.size() == 0) {
EXML_ERROR("No error detected ???");
return;
@ -156,8 +147,7 @@ void exml::Document::displayError(void)
#endif
}
void exml::Document::createError(const etk::UString& _data, int32_t _pos, const exml::filePos& _filePos, const etk::UString& _comment)
{
void exml::Document::createError(const etk::UString& _data, int32_t _pos, const exml::filePos& _filePos, const etk::UString& _comment) {
m_comment = _comment;
m_Line = _data.extractLine(_pos);
m_filePos = _filePos;

View File

@ -13,10 +13,8 @@
#include <etk/unicode.h>
#include <etk/Vector.h>
namespace exml
{
class Document : public exml::Element
{
namespace exml {
class Document : public exml::Element {
public:
/**
* @brief Constructor
@ -27,18 +25,22 @@ namespace exml
*/
virtual ~Document(void) { };
private:
unicode::charset_te m_charset;
enum unicode::charset m_charset;
public:
/**
* @brief get the current charset of the Parsing
* @param[in] _charset The new charset
*/
virtual void setCharset(unicode::charset_te _charset) { m_charset = _charset; };
virtual void setCharset(enum unicode::charset _charset) {
m_charset = _charset;
};
/**
* @brief get the current charset of the Parsing
* @return The current charset
*/
virtual unicode::charset_te getCharset(void) const { return m_charset; };
virtual enum unicode::charset getCharset(void) const {
return m_charset;
};
private:
bool m_caseSensitive; // check the case sensitive of the nodes and attribute
public:
@ -46,12 +48,16 @@ namespace exml
* @brief Enable or diasable the case sensitive (must be done before the call of parsing)
* @param[in] _val true if enable; false else.
*/
virtual void setCaseSensitive(bool _val) { m_caseSensitive = _val; };
virtual void setCaseSensitive(bool _val) {
m_caseSensitive = _val;
};
/**
* @brief get the status of case sensitive mode.
* @return true if case sensitive is active
*/
virtual bool getCaseSensitive(void) const { return m_caseSensitive; };
virtual bool getCaseSensitive(void) const {
return m_caseSensitive;
};
public:
/**
* @brief parse a string that contain an XML
@ -91,16 +97,26 @@ namespace exml
etk::UString m_Line;
exml::filePos m_filePos;
public:
void displayErrorWhenDetected(void) { m_writeErrorWhenDetexted=true; };
void notDisplayErrorWhenDetected(void) { m_writeErrorWhenDetexted=false; };
void displayErrorWhenDetected(void) {
m_writeErrorWhenDetexted = true;
};
void notDisplayErrorWhenDetected(void) {
m_writeErrorWhenDetexted = false;
};
void createError(const etk::UString& _data, int32_t _pos, const exml::filePos& _filePos, const etk::UString& _comment);
void displayError(void);
public: // herited function:
virtual nodeType_te getType(void) const { return typeDocument; };
virtual enum nodeType getType(void) const {
return typeDocument;
};
bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual exml::Document* toDocument(void) { return this; };
virtual const exml::Document* toDocument(void) const { return this; };
virtual exml::Document* toDocument(void) {
return this;
};
virtual const exml::Document* toDocument(void) const {
return this;
};
};
};

View File

@ -28,14 +28,14 @@ exml::Element::~Element(void) {
m_listSub.clear();
}
exml::nodeType_te exml::Element::getType(int32_t _id) {
enum exml::nodeType exml::Element::getType(int32_t _id) {
exml::Node* tmpp = getNode(_id);
if (NULL == tmpp) {
return exml::typeUnknow;
}
return tmpp->getType();
}
const exml::nodeType_te exml::Element::getType(int32_t _id) const {
const enum exml::nodeType exml::Element::getType(int32_t _id) const {
const exml::Node* tmpp = getNode(_id);
if (NULL == tmpp) {
return exml::typeUnknow;
@ -50,8 +50,7 @@ exml::Node* exml::Element::getNode(int32_t _id) {
return m_listSub[_id];
}
const exml::Node* exml::Element::getNode(int32_t _id) const
{
const exml::Node* exml::Element::getNode(int32_t _id) const {
if (_id <0 || _id>m_listSub.size()) {
return NULL;
}
@ -59,16 +58,15 @@ const exml::Node* exml::Element::getNode(int32_t _id) const
}
exml::Element* exml::Element::getElement(int32_t _id)
{
exml::Element* exml::Element::getElement(int32_t _id) {
exml::Node* tmpp = getNode(_id);
if (NULL == tmpp) {
return NULL;
}
return tmpp->toElement();
}
const exml::Element* exml::Element::getElement(int32_t _id) const
{
const exml::Element* exml::Element::getElement(int32_t _id) const {
const exml::Node* tmpp = getNode(_id);
if (NULL == tmpp) {
return NULL;
@ -76,26 +74,7 @@ const exml::Element* exml::Element::getElement(int32_t _id) const
return tmpp->toElement();
}
exml::Element* exml::Element::getNamed(const etk::UString& _name)
{
if (_name.size() == 0) {
return NULL;
}
for (int32_t iii=0; iii<m_listSub.size(); iii++) {
if( NULL != m_listSub[iii]
&& m_listSub[iii]->getType() == exml::typeElement
&& m_listSub[iii]->getValue() == _name) {
if (NULL == m_listSub[iii]) {
return NULL;
}
return m_listSub[iii]->toElement();
}
}
return NULL;
}
const exml::Element* exml::Element::getNamed(const etk::UString& _name) const
{
exml::Element* exml::Element::getNamed(const etk::UString& _name) {
if (_name.size() == 0) {
return NULL;
}
@ -112,8 +91,24 @@ const exml::Element* exml::Element::getNamed(const etk::UString& _name) const
return NULL;
}
void exml::Element::append(exml::Node* _node)
{
const exml::Element* exml::Element::getNamed(const etk::UString& _name) const {
if (_name.size() == 0) {
return NULL;
}
for (int32_t iii=0; iii<m_listSub.size(); iii++) {
if( NULL != m_listSub[iii]
&& m_listSub[iii]->getType() == exml::typeElement
&& m_listSub[iii]->getValue() == _name) {
if (NULL == m_listSub[iii]) {
return NULL;
}
return m_listSub[iii]->toElement();
}
}
return NULL;
}
void exml::Element::append(exml::Node* _node) {
if (_node == NULL) {
EXML_ERROR("Try to set an empty node");
return;
@ -131,8 +126,7 @@ void exml::Element::append(exml::Node* _node)
m_listSub.pushBack(_node);
}
etk::UString exml::Element::getText(void)
{
etk::UString exml::Element::getText(void) {
// TODO : add more capabilities ...
etk::UString res;
for (int32_t iii=0; iii<m_listSub.size(); iii++) {
@ -143,9 +137,7 @@ etk::UString exml::Element::getText(void)
return res;
}
bool exml::Element::iGenerate(etk::UString& _data, int32_t _indent) const
{
bool exml::Element::iGenerate(etk::UString& _data, int32_t _indent) const {
addIndent(_data, _indent);
_data += "<";
_data += m_value;
@ -178,8 +170,7 @@ bool exml::Element::iGenerate(etk::UString& _data, int32_t _indent) const
}
bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode)
{
bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode) {
EXML_PARSE_ELEMENT(" start subParse ... " << _pos << " " << _filePos);
for (int32_t iii=_pos; iii<_data.size(); iii++) {
_filePos.check(_data[iii]);
@ -437,8 +428,7 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
return false;
}
bool exml::Element::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc)
{
bool exml::Element::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_PARSE_ELEMENT("start parse : 'element' named='" << m_value << "'");
// note : When start parsing the upper element must have set the value of the element and set the position after this one
m_pos=_filePos;
@ -493,8 +483,7 @@ bool exml::Element::iParse(const etk::UString& _data, int32_t& _pos, bool _caseS
return false;
}
void exml::Element::clear(void)
{
void exml::Element::clear(void) {
exml::AttributeList::clear();
for (int32_t iii=0; iii<m_listSub.size(); iii++) {
if (NULL!=m_listSub[iii]) {

View File

@ -13,10 +13,8 @@
#include <etk/Vector.h>
#include <exml/AttributeList.h>
namespace exml
{
class Element : public AttributeList
{
namespace exml {
class Element : public AttributeList {
public:
/**
* @brief Constructor
@ -26,7 +24,10 @@ namespace exml
* @brief Constructor
* @param[in] _value Element name;
*/
Element(const etk::UString& _value) : exml::AttributeList(_value) { };
Element(const etk::UString& _value) :
exml::AttributeList(_value) {
};
/**
* @brief Destructor
*/
@ -38,7 +39,9 @@ namespace exml
* @brief get the number of sub element in the node (can be exml::Comment ; exml::Element ; exml::Text :exml::Declaration).
* @return a number >=0.
*/
int32_t size(void) const { return m_listSub.size(); };
int32_t size(void) const {
return m_listSub.size();
};
/**
* @brief add a node at the element (not exml::Attribute (move in the attribute automaticly).
* @param[in] _node Pointer of the node to add.
@ -49,8 +52,8 @@ namespace exml
* @param[in] _id Id of the element.
* @return the Current type of the element or exml::typeUnknow.
*/
nodeType_te getType(int32_t _id);
const nodeType_te getType(int32_t _id) const;
enum nodeType getType(int32_t _id);
const enum nodeType getType(int32_t _id) const;
/**
* @brief get the Node pointer of the element id.
* @param[in] _id Id of the element.
@ -80,11 +83,17 @@ namespace exml
protected:
bool subParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode=false);
public: // herited function:
virtual nodeType_te getType(void) const { return typeElement; };
virtual enum nodeType getType(void) const {
return typeElement;
};
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual exml::Element* toElement(void) { return this; };
virtual const exml::Element* toElement(void) const { return this; };
virtual exml::Element* toElement(void) {
return this;
};
virtual const exml::Element* toElement(void) const {
return this;
};
virtual void clear(void);
};
};

View File

@ -34,7 +34,7 @@ namespace exml
class Element;
class Text;
typedef enum {
enum nodeType {
typeUnknow, //!< might be an error ...
typeNode, //!< might be an error ...
typeDocument, //!< all the file main access
@ -43,19 +43,35 @@ namespace exml
typeElement, //!< the <XXX> ... </XXX>
typeComment, //!< comment node : <!-- -->
typeText, //!< <XXX> InsideText </XXX>
} nodeType_te;
};
class filePos
{
class filePos {
private:
int32_t m_col;
int32_t m_line;
public:
filePos(void) : m_col(0),m_line(0) { };
filePos(int32_t _line, int32_t _col) : m_col(_col),m_line(_line) { };
filePos(void) :
m_col(0),
m_line(0) {
};
filePos(int32_t _line, int32_t _col) :
m_col(_col),
m_line(_line) {
};
~filePos(void) { };
filePos& operator ++(void) { m_col++; return *this; };
filePos& operator --(void) { m_col--; if(m_col<0) { m_col=0;} return *this; };
filePos& operator ++(void) {
m_col++;
return *this;
};
filePos& operator --(void) {
m_col--;
if(m_col<0) {
m_col=0;
}
return *this;
};
const filePos& operator +=(const filePos& _obj) {
if (_obj.m_line == 0) {
m_col += _obj.m_col;
@ -74,7 +90,10 @@ namespace exml
m_line = _obj.m_line;
return *this;
}
void newLine(void) { m_col=0; m_line++; };
void newLine(void) {
m_col=0;
m_line++;
};
bool check(const etk::UChar& _val) {
m_col++;
if (_val == '\n') {
@ -91,18 +110,24 @@ namespace exml
m_col = 0;
m_line = 0;
}
int32_t getCol(void) const { return m_col; };
int32_t getLine(void) const { return m_line; };
int32_t getCol(void) const {
return m_col;
};
int32_t getLine(void) const {
return m_line;
};
};
etk::CCout& operator <<(etk::CCout& _os, const filePos& _obj);
class Node
{
class Node {
public:
/**
* @brief basic element of a xml structure
*/
Node(void) : m_pos(0,0) { };
Node(void) :
m_pos(0,0) {
};
/**
* @brief basic element of a xml structure
* @param[in] value of the node
@ -128,14 +153,18 @@ namespace exml
* @param[in] current indentation of the file
* @return false if an error occured.
*/
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const { return true; };
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const {
return true;
};
protected:
exml::filePos m_pos; //!< position in the readed file == > not correct when the file is generated
public:
/**
* @brief get the current position where the element is in the file
*/
const exml::filePos& getPos(void) { return m_pos; };
const exml::filePos& getPos(void) {
return m_pos;
};
protected:
etk::UString m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
public:
@ -143,18 +172,24 @@ namespace exml
* @brief set the value of the node.
* @param[in] _value New value of the node.
*/
virtual void setValue(etk::UString _value) { m_value = _value; };
virtual void setValue(etk::UString _value) {
m_value = _value;
};
/**
* @brief get the current element Value.
* @return the reference of the string value.
*/
virtual const etk::UString& getValue(void) const { return m_value; };
virtual const etk::UString& getValue(void) const {
return m_value;
};
public:
/**
* @brief get the node type.
* @return the type of the Node.
*/
virtual nodeType_te getType(void) const { return typeNode; };
virtual enum nodeType getType(void) const {
return typeNode;
};
protected:
/**
* @brief add indentation of the string input.
@ -187,69 +222,105 @@ namespace exml
* @brief Cast the element in a Document if it is possible.
* @return pointer on the class or NULL.
*/
virtual exml::Document* toDocument(void) { return NULL; };
virtual const exml::Document* toDocument(void) const { return NULL; };
virtual exml::Document* toDocument(void) {
return NULL;
};
virtual const exml::Document* toDocument(void) const {
return NULL;
};
/**
* @brief Cast the element in a Attribute if it is possible.
* @return pointer on the class or NULL.
*/
virtual exml::Attribute* toAttribute(void) { return NULL; };
virtual const exml::Attribute* toAttribute(void) const { return NULL; };
virtual exml::Attribute* toAttribute(void) {
return NULL;
};
virtual const exml::Attribute* toAttribute(void) const {
return NULL;
};
/**
* @brief Cast the element in a Comment if it is possible.
* @return pointer on the class or NULL.
*/
virtual exml::Comment* toComment(void) { return NULL; };
virtual const exml::Comment* toComment(void) const { return NULL; };
virtual exml::Comment* toComment(void) {
return NULL;
};
virtual const exml::Comment* toComment(void) const {
return NULL;
};
/**
* @brief Cast the element in a Declaration if it is possible.
* @return pointer on the class or NULL.
*/
virtual exml::Declaration* toDeclaration(void) { return NULL; };
virtual const exml::Declaration* toDeclaration(void) const { return NULL; };
virtual exml::Declaration* toDeclaration(void) {
return NULL;
};
virtual const exml::Declaration* toDeclaration(void) const {
return NULL;
};
/**
* @brief Cast the element in a Element if it is possible.
* @return pointer on the class or NULL.
*/
virtual exml::Element* toElement(void) { return NULL; };
virtual const exml::Element* toElement(void) const { return NULL; };
virtual exml::Element* toElement(void) {
return NULL;
};
virtual const exml::Element* toElement(void) const {
return NULL;
};
/**
* @brief Cast the element in a Text if it is possible.
* @return pointer on the class or NULL.
*/
virtual exml::Text* toText(void) { return NULL; };
virtual const exml::Text* toText(void) const{ return NULL; };
virtual exml::Text* toText(void) {
return NULL;
};
virtual const exml::Text* toText(void) const{
return NULL;
};
/**
* @brief check if the node is a exml::Document
* @return true if the node is a exml::Document
*/
bool isDocument(void) const { return getType() == exml::typeDocument; };
bool isDocument(void) const {
return getType() == exml::typeDocument;
};
/**
* @brief check if the node is a exml::Attribute
* @return true if the node is a exml::Attribute
*/
bool isAttribute(void) const { return getType() == exml::typeAttribute; };
bool isAttribute(void) const {
return getType() == exml::typeAttribute;
};
/**
* @brief check if the node is a exml::Comment
* @return true if the node is a exml::Comment
*/
bool isComment(void) const { return getType() == exml::typeComment; };
bool isComment(void) const {
return getType() == exml::typeComment;
};
/**
* @brief check if the node is a exml::Declaration
* @return true if the node is a exml::Declaration
*/
bool isDeclaration(void) const { return getType() == exml::typeDeclaration; };
bool isDeclaration(void) const {
return getType() == exml::typeDeclaration;
};
/**
* @brief check if the node is a exml::Element
* @return true if the node is a exml::Element
*/
bool isElement(void) const { return getType() == exml::typeElement; };
bool isElement(void) const {
return getType() == exml::typeElement;
};
/**
* @brief check if the node is a exml::Text
* @return true if the node is a exml::Text
*/
bool isText(void) const { return getType() == exml::typeText; };
bool isText(void) const {
return getType() == exml::typeText;
};
/**
* @brief clear the Node

View File

@ -34,11 +34,17 @@ namespace exml {
*/
int32_t countLines(void) const;
public: // herited function:
virtual nodeType_te getType(void) const { return typeText; };
virtual enum nodeType getType(void) const {
return typeText;
};
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual exml::Text* toText(void) { return this; };
virtual const exml::Text* toText(void) const{ return this; };
virtual exml::Text* toText(void) {
return this;
};
virtual const exml::Text* toText(void) const{
return this;
};
};
class TextCDATA : public Text {
public:

View File

@ -14,15 +14,13 @@
#undef __class__
#define __class__ "test"
class testCheck
{
class testCheck {
public:
etk::UString m_ref;
etk::UString m_input;
int32_t m_errorPos; // -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
testCheck(void) {};
void set(const etk::UString& _ref, int32_t _pos, const etk::UString& _input)
{
void set(const etk::UString& _ref, int32_t _pos, const etk::UString& _input) {
m_ref = _ref;
m_input = _input;
m_errorPos = _pos;
@ -31,8 +29,7 @@ class testCheck
etk::Vector<testCheck> l_list;
void init(void)
{
void init(void) {
etk::UString reference;
etk::UString input;
testCheck check;
@ -281,8 +278,7 @@ void init(void)
l_list.pushBack(check);
}
int main(int argc, const char *argv[])
{
int main(int argc, const char *argv[]) {
debug::setGeneralLevel(etk::LOG_LEVEL_VERBOSE);
init();
int32_t countError = 0;