init
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
#include <cstdlib> // fix Unix compatibility
|
||||
|
||||
namespace XML {
|
||||
class XML_API IReaderCallback
|
||||
{
|
||||
public:
|
||||
virtual ~IReaderCallback() { }
|
||||
virtual void openChild(const char* name, const char** attributeName, const char** attributeValue, const size_t nAttribute) = 0;
|
||||
virtual void processChildData(const char* data) = 0;
|
||||
virtual void closeChild() = 0;
|
||||
};
|
||||
|
||||
class XML_API IReaderCallBack : public IReaderCallback { };
|
||||
|
||||
class XML_API IReader
|
||||
{
|
||||
public:
|
||||
virtual bool processData(const void* buffer, const size_t size) = 0;
|
||||
virtual void release() = 0;
|
||||
protected:
|
||||
virtual ~IReader() { }
|
||||
};
|
||||
|
||||
extern XML_API IReader* createReader(IReaderCallback& callback);
|
||||
} // namespace XML
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
namespace XML {
|
||||
class XML_API IWriterCallback
|
||||
{
|
||||
public:
|
||||
virtual ~IWriterCallback() { }
|
||||
virtual void write(const char* sString) = 0;
|
||||
};
|
||||
|
||||
class XML_API IWriterCallBack : public IWriterCallback { };
|
||||
|
||||
class XML_API IWriter
|
||||
{
|
||||
public:
|
||||
virtual bool openChild(const char* name) = 0;
|
||||
virtual bool setAttribute(const char* name, const char* value) = 0;
|
||||
virtual bool setChildData(const char* data) = 0;
|
||||
virtual bool closeChild() = 0;
|
||||
virtual void release() = 0;
|
||||
protected:
|
||||
virtual ~IWriter() { }
|
||||
};
|
||||
|
||||
extern XML_API IWriter* createWriter(IWriterCallback& callback);
|
||||
} // namespace XML
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
#include "IXMLNode.h"
|
||||
#include <string>
|
||||
#include <cstdlib> // fix Unix compatibility
|
||||
|
||||
namespace XML {
|
||||
/**
|
||||
* @class IXMLHandler
|
||||
* @author Serrière Guillaume (INRIA/Loria)
|
||||
* @brief This class is design to help about XML manipulation.
|
||||
* @sa XML
|
||||
*/
|
||||
class XML_API IXMLHandler
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Release the handler.
|
||||
*/
|
||||
virtual void release() = 0;
|
||||
|
||||
//Parsing
|
||||
/**
|
||||
* @brief Parse file points by sPath and return the root name of the document.
|
||||
* @param path [in] : Path to the File
|
||||
* @return The root node of the document, or NULL if there is an error.
|
||||
*/
|
||||
virtual IXMLNode* parseFile(const char* path) = 0;
|
||||
|
||||
/**
|
||||
* @brief Parse the string sString on uiSize caracters and return the root name of the document.
|
||||
* @param str [in] : String which contains the XML
|
||||
* @param size [in] : Size of the part to analyze
|
||||
* @return The root node of the parse part, or NULL if there is an error.
|
||||
*/
|
||||
virtual IXMLNode* parseString(const char* str, const size_t& size) = 0;
|
||||
|
||||
//XML extraction
|
||||
/**
|
||||
* @brief Write the XML corresponding to the node rNode in the file points by sPath. If the file exists
|
||||
* it will be erase.
|
||||
* @param node [in] : The node to write.
|
||||
* @param path [in] : The path to the file.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
virtual bool writeXMLInFile(const IXMLNode& node, const char* path) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the description of the last error that ocurred
|
||||
* @return A string object containing the error description
|
||||
*/
|
||||
virtual std::string getLastErrorString() const = 0;
|
||||
|
||||
protected:
|
||||
virtual ~IXMLHandler() { }
|
||||
};
|
||||
|
||||
extern XML_API IXMLHandler* createXMLHandler();
|
||||
} // namespace XML
|
||||
@@ -0,0 +1,110 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
#include <string>
|
||||
#include <cstdlib> // fix Unix compatibility
|
||||
|
||||
namespace XML {
|
||||
/**
|
||||
* @class IXMLNode
|
||||
* @author Serrière Guillaume (INRIA/Loria)
|
||||
* @brief Symbolize a node in a XML tree structure.
|
||||
* @sa XML
|
||||
*/
|
||||
class XML_API IXMLNode
|
||||
{
|
||||
public:
|
||||
virtual void release() = 0;
|
||||
|
||||
virtual const char* getName() const = 0;
|
||||
|
||||
//Attribute
|
||||
/**
|
||||
* @brief Add the attribute name with value
|
||||
* value to the node.
|
||||
* @param name [in] : Name of the attribute
|
||||
* @param value [in] : Value of the attribute
|
||||
* @return true in success, false otherwise
|
||||
*/
|
||||
virtual bool addAttribute(const char* name, const char* value) = 0;
|
||||
|
||||
/**
|
||||
* @brief Indicate if an attribute exists or not.
|
||||
* @param name [in] : Name of the attribute
|
||||
* @return true if attribute exists, false otherwise
|
||||
*/
|
||||
virtual bool hasAttribute(const char* name) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Return the value of an attribute.
|
||||
* @param name [in] : Name of the attribute
|
||||
* @return Value of the attribute
|
||||
*/
|
||||
virtual const char* getAttribute(const char* name) const = 0;
|
||||
|
||||
//PCDATA
|
||||
/**
|
||||
* @brief Set the PCDATA of the node.
|
||||
* @param data [in] : Value of the PCDATA
|
||||
*/
|
||||
virtual void setPCData(const char* data) = 0;
|
||||
|
||||
/**
|
||||
* @brief Apppend a string to the current PCDATA of the node
|
||||
* @param data [in] : Value of teh PCDATA to append
|
||||
*/
|
||||
virtual void appendPCData(const char* data) = 0;
|
||||
|
||||
/**
|
||||
* @brief Return the PCDATA of the node.
|
||||
* @return Value of PCDATA
|
||||
*/
|
||||
virtual const char* getPCData() const = 0;
|
||||
|
||||
//Child
|
||||
/**
|
||||
* @brief Add a node child of the
|
||||
* @param node [in] : The Node that will became the new child
|
||||
*/
|
||||
virtual void addChild(IXMLNode* node) = 0;
|
||||
|
||||
/**
|
||||
* @brief Return the ith child of the node.
|
||||
* @param index [in] : index of the child.
|
||||
* @return The ith child of the node.
|
||||
*/
|
||||
virtual IXMLNode* getChild(const size_t index) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Return the first child with the name name.
|
||||
* @param name [in]] : Name of th child
|
||||
* @return The first child of the node which name is name.
|
||||
*/
|
||||
virtual IXMLNode* getChildByName(const char* name) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Return the amount of child the node has.
|
||||
* @return Amount of child.
|
||||
*/
|
||||
virtual size_t getChildCount() const = 0;
|
||||
|
||||
//XML generation
|
||||
/**
|
||||
* @brief Return a string which contains the XML of the node. The string is dynamically instantiate so
|
||||
* it requires to be free.
|
||||
* @param depth [in] : Amount of indentation
|
||||
* @return XML string describing the node and its childs.
|
||||
*/
|
||||
virtual char* getXML(const size_t depth = 0) const = 0;
|
||||
|
||||
protected:
|
||||
virtual ~IXMLNode() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create a new node with the name name. The node is created dynamically and requires to be free.
|
||||
* @param name [in] : Name of the node
|
||||
* @return New node
|
||||
*/
|
||||
extern XML_API IXMLNode* createNode(const char* name);
|
||||
} // namespace XML
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "IReader.h"
|
||||
|
||||
namespace XML {
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
template <class TOwnerClass>
|
||||
class TReaderCallbackProxy1 final : public IReaderCallback
|
||||
{
|
||||
public:
|
||||
TReaderCallbackProxy1(TOwnerClass& ownerObject,
|
||||
void (TOwnerClass::*mfpOpenChild)(const char* name, const char** attributeName, const char** attributeValue, size_t nAttribute),
|
||||
void (TOwnerClass::*mfpProcessChildData)(const char* data), void (TOwnerClass::*mfpCloseChild)())
|
||||
: m_ownerObject(ownerObject), m_mfpOpenChild(mfpOpenChild), m_mfpProcessChildData(mfpProcessChildData), m_mfpCloseChild(mfpCloseChild) { }
|
||||
|
||||
void openChild(const char* name, const char** attributeName, const char** attributeValue, const size_t nAttribute) override
|
||||
{
|
||||
if (m_mfpOpenChild) { m_ownerObject.m_mfpOpenChild(name, attributeName, attributeValue, nAttribute); }
|
||||
}
|
||||
|
||||
void processChildData(const char* data) override { if (m_mfpProcessChildData) { m_ownerObject.m_mfpProcessChildData(data); } }
|
||||
void closeChild() override { if (m_mfpCloseChild) { m_ownerObject.m_mfpCloseChild(); } }
|
||||
|
||||
protected:
|
||||
TOwnerClass& m_ownerObject;
|
||||
void (TOwnerClass::*m_mfpOpenChild)(const char* name, const char** attributeName, const char** attributeValue, size_t nAttribute);
|
||||
void (TOwnerClass::*m_mfpProcessChildData)(const char* data);
|
||||
void (TOwnerClass::*m_mfpCloseChild)();
|
||||
};
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
template <class TOwnerClass,
|
||||
void (TOwnerClass::*TMfpOpenChild)(const char* name, const char** attributeName, const char** attributeValue, size_t nAttribute),
|
||||
void (TOwnerClass::*TMfpProcessChildData)(const char* data), void (TOwnerClass::*mfpCloseChild)()>
|
||||
class TReaderCallbackProxy2 final : public IReaderCallback
|
||||
{
|
||||
public:
|
||||
TReaderCallbackProxy2(TOwnerClass ownerObject)
|
||||
: m_ownerObject(ownerObject), m_mfpOpenChild(TMfpOpenChild), m_mfpProcessChildData(TMfpProcessChildData), m_mfpCloseChild(mfpCloseChild) { }
|
||||
|
||||
void openChild(const char* name, const char** attributeName, const char** attributeValue, const size_t nAttribute) override
|
||||
{
|
||||
if (TMfpOpenChild) { m_ownerObject.mfpOpenChild(name, attributeName, attributeValue, nAttribute); }
|
||||
}
|
||||
|
||||
void processChildData(const char* data) override { if (TMfpProcessChildData) { m_ownerObject.mfpProcessChildData(data); } }
|
||||
void closeChild() override { if (mfpCloseChild) { m_ownerObject.mfpCloseChild(); } }
|
||||
|
||||
protected:
|
||||
TOwnerClass& m_ownerObject;
|
||||
void (TOwnerClass::*m_mfpOpenChild)(const char* name, const char** attributeName, const char** attributeValue, size_t nAttribute);
|
||||
void (TOwnerClass::*m_mfpProcessChildData)(const char* data);
|
||||
void (TOwnerClass::*m_mfpCloseChild)();
|
||||
};
|
||||
} // namespace XML
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "IWriter.h"
|
||||
|
||||
namespace XML {
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
template <class TOwnerClass>
|
||||
class TWriterCallbackProxy1 final : public IWriterCallback
|
||||
{
|
||||
public:
|
||||
TWriterCallbackProxy1(TOwnerClass& ownerObject, void (TOwnerClass::*mfpWrite)(const char* str))
|
||||
: m_ownerObject(ownerObject), m_mfpWrite(mfpWrite) { }
|
||||
|
||||
void write(const char* str) override { if (m_mfpWrite) { m_ownerObject.m_mfpWrite(str); } }
|
||||
|
||||
protected:
|
||||
TOwnerClass& m_ownerObject;
|
||||
void (TOwnerClass::*m_mfpWrite)(const char* str);
|
||||
};
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
template <class TOwnerClass, void (TOwnerClass::*TMfpWrite)(const char* str)>
|
||||
class TWriterCallbackProxy2 final : public IWriterCallback
|
||||
{
|
||||
public:
|
||||
TWriterCallbackProxy2(TOwnerClass ownerObject) : m_ownerObject(ownerObject), m_mfpWrite(TMfpWrite) { }
|
||||
|
||||
void write(const char* str) override { if (TMfpWrite) { m_ownerObject.mfpWrite(str); } }
|
||||
|
||||
protected:
|
||||
TOwnerClass& m_ownerObject;
|
||||
void (TOwnerClass::*m_mfpWrite)(const char* str);
|
||||
};
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
} // namespace XML
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <ov_common_defines.h>
|
||||
|
||||
#if defined XML_Shared
|
||||
# if defined TARGET_OS_Windows
|
||||
# define XML_API_Export __declspec(dllexport)
|
||||
# define XML_API_Import __declspec(dllimport)
|
||||
# elif defined TARGET_OS_Linux
|
||||
# define XML_API_Export __attribute__((visibility("default")))
|
||||
# define XML_API_Import __attribute__((visibility("default")))
|
||||
# else
|
||||
# define XML_API_Export
|
||||
# define XML_API_Import
|
||||
# endif
|
||||
#else
|
||||
# define XML_API_Export
|
||||
# define XML_API_Import
|
||||
#endif
|
||||
|
||||
#if defined XML_Exports
|
||||
# define XML_API XML_API_Export
|
||||
#else
|
||||
# define XML_API XML_API_Import
|
||||
#endif
|
||||
Reference in New Issue
Block a user