gambas-source-code/gb.xml/src/element.h

142 lines
5.6 KiB
C
Raw Normal View History

/***************************************************************************
(c) 2012 Adrien Prokopowicz <prokopy@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
[GB.XML] OPT : A few compilation optimizations in headers inclusions. OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems. OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification). OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes. OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list. OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser). OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file. OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text. OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object. OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations. BUG : When loading a document from a file, now correctly releases the file data. BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results. git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#ifndef ELEMENT_H
#define ELEMENT_H
#include "node.h"
#include "utils.h"
class Attribute : public Node
[GB.XML] OPT : A few compilation optimizations in headers inclusions. OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems. OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification). OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes. OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list. OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser). OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file. OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text. OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object. OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations. BUG : When loading a document from a file, now correctly releases the file data. BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results. git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
{
public:
Attribute();
Attribute(const char *nattrName, const size_t nlenAttrName);
Attribute(const char *nattrName, const size_t nlenAttrName,
const char *nattrVal, const size_t nlenAttrVal);
~Attribute();
void setName(const char *nattrName, const size_t nlenAttrName);
void setValue(const char *nattrVal, const size_t nlenAttrVal);
char *attrName;
size_t lenAttrName;
char *attrValue;
size_t lenAttrValue;
virtual Node::Type getType();
virtual void addStringLen(size_t *len, int indent = 0);
virtual void addString(char **data, int indent = 0);
virtual void setTextContent(const char *ncontent, const size_t nlen);
virtual void addTextContentLen(size_t &len);
virtual void addTextContent(char *&data);
virtual void NewGBObject();
};
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
class Element : public Node
{
public:
Element();
Element(const char *ntagName, size_t nlenTagName);
virtual ~Element();
virtual Type getType();
//Tag Name
void setTagName(const char *ntagName, size_t nlenTagName);//(re)defines the tag name
bool isSingle();
char *tagName;
size_t lenTagName;
//Node tree
void appendChild(Node *newChild);//Adds a new child after the last one
void prependChild(Node *newChild);
void removeChild(Node *child);//Removes a child from the node
void removeKeepChild(Node *child);//Removes a child from the node, but doesn't destroys it
void replaceChild(Node *oldChild, Node *newChild);
bool insertAfter(Node *child, Node *newChild);
bool insertBefore(Node *child, Node *newChild);
void appendText(const char *data, const size_t lenData);
void appendFromText(char *data, const size_t lenData);
void getGBChildrenByTagName(const char *ctagName, const size_t clenTagName, GB_ARRAY *array, const int depth = -1);
void addGBChildrenByTagName(const char *compTagName, const size_t compLenTagName, GB_ARRAY *array, const int depth = -1);
void getGBChildrenByAttributeValue(const char *attrName, const size_t lenAttrName,
const char *attrValue, const size_t lenAttrValue,
GB_ARRAY *array, const int depth = -1);
void addGBChildrenByAttributeValue(const char *attrName, const size_t lenAttrName,
const char *attrValue, const size_t lenAttrValue,
GB_ARRAY *array, const int depth = -1);
Element** getChildrenByTagName(const char *ctagName, const size_t clenTagName, size_t &lenArray, const int depth = -1);
Element* getFirstChildByTagName(const char *ctagName, const size_t clenTagName, const int depth = -1);
void addChildrenByTagName(const char *compTagName, const size_t compLenTagName, Element** &array, size_t &lenArray, const int depth = -1);
void getGBAllChildren(GB_ARRAY *array);
void addGBAllChildren(GB_ARRAY *array);
void getGBChildren(GB_ARRAY *array);
void getGBChildElements(GB_ARRAY *array);
Element* firstChildElement();
Element* lastChildElement();
Element* previousSibling();
Element* nextSibling();
[GB.XML] OPT : A few compilation optimizations in headers inclusions. OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems. OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification). OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes. OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list. OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser). OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file. OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text. OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object. OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations. BUG : When loading a document from a file, now correctly releases the file data. BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results. git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
Node *firstChild;
Node *lastChild;
size_t childCount;
//Attributes
void addAttribute(const char *nattrName, const size_t nlenAttrName);//Adds a new attribute
void addAttribute(const char *nattrName, const size_t nlenAttrName,
const char *nattrVal, const size_t nlenAttrVal);
Attribute* getAttribute(const char *nattrName, const size_t nlenAttrName);//Looks for attribute, and returns its value
void setAttribute(const char *nattrName, const size_t nlenAttrName,
const char *nattrVal, const size_t nlenAttrVal);//Looks for attribute, sets its value or add it if attribute is not found
bool attributeContains(const char *attrName, size_t lenAttrName, char *value, size_t lenValue);
Attribute *firstAttribute;
Attribute *lastAttribute;
size_t attributeCount;
//String output
virtual void addStringLen(size_t *len, int indent = 0);
virtual void addString(char **data, int indent = 0);
//Text Content
virtual void setTextContent(const char *ncontent, const size_t nlen);
virtual void addTextContentLen(size_t &len);
virtual void addTextContent(char *&data);
//Parser
static void GBfromText(char *data, const size_t lendata, GB_ARRAY *array);
static Node** fromText(char *data, const size_t lendata, size_t *nodeCount) throw(XMLParseException);
//Gambas object
virtual void NewGBObject();
static const char* singleElements;
#ifndef HELEMENT_H
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
};
#endif
#endif // ELEMENT_H