init
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
#include <climits>
|
||||
|
||||
namespace EBML {
|
||||
/**
|
||||
* \class CIdentifier
|
||||
* \author Yann Renard (INRIA/IRISA)
|
||||
* \date 2006-08-07
|
||||
* \brief Base class to work with EBML identifiers
|
||||
*
|
||||
* This class is used in order to work on EBML identifier.
|
||||
* It handles 64 bits values for now, but could easily be
|
||||
* changed to handle bigger values if needed.
|
||||
*
|
||||
* Be sure to look at http://ebml.sourceforge.net/specs/ in
|
||||
* order to understand what an identifier is and how it works
|
||||
*/
|
||||
class EBML_API CIdentifier
|
||||
{
|
||||
public:
|
||||
|
||||
/** \name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* \brief Basic constructor
|
||||
*
|
||||
* Initializes the identifier to 0.
|
||||
*/
|
||||
CIdentifier() : m_id(ULLONG_MAX) {}
|
||||
/**
|
||||
* \brief Integer based constructor
|
||||
* \param id [in] : The value to use
|
||||
*
|
||||
* Initializes the identifier to the given 64 bits value.
|
||||
*/
|
||||
CIdentifier(const uint64_t id) : m_id(id) {}
|
||||
/**
|
||||
* \brief 32 bits integer based constructor
|
||||
* \param id1 [in] : the first part of the identifier
|
||||
* \param id2 [in] : the second part of the identifier
|
||||
*
|
||||
* Builds up the 64 bits identifier given its two 32 bits
|
||||
* components.
|
||||
*/
|
||||
CIdentifier(const size_t id1, const size_t id2) : m_id((uint64_t(id1) << 32) + id2) {}
|
||||
/**
|
||||
* \brief Copy constructor
|
||||
* \param id [in] : The source identifier to use
|
||||
*
|
||||
* Initializes this identifier to the same value as
|
||||
* the given source identifier.
|
||||
*/
|
||||
CIdentifier(const CIdentifier& id) : m_id(id.m_id) {}
|
||||
|
||||
//@}
|
||||
/** \name Operators */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* \brief Copy operator
|
||||
* \param id [in] : The source identifier to copy from
|
||||
* \return a const reference on this identifier
|
||||
*
|
||||
* Initializes this identifier to the same value as
|
||||
* the given source identifier.
|
||||
*/
|
||||
const CIdentifier& operator=(const CIdentifier& id);
|
||||
|
||||
/**
|
||||
* \brief Equality comparison operator
|
||||
* \param id1 [in] : The first identifier to compare
|
||||
* \param id2 [in] : The second identifier to compare
|
||||
* \return \e true when the identifiers are equal, \e false
|
||||
* when they are different.
|
||||
*
|
||||
* This function compares the two 64 bits values.
|
||||
*/
|
||||
friend EBML_API bool operator==(const CIdentifier& id1, const CIdentifier& id2);
|
||||
/**
|
||||
* \brief Difference comparison operator
|
||||
* \param id1 [in] : The first identifier to compare
|
||||
* \param id2 [in] : The second identifier to compare
|
||||
* \return \e true when the identifiers are different, \e false
|
||||
* when they are equal.
|
||||
*
|
||||
* This function compares the two 64 bits values.
|
||||
*/
|
||||
friend EBML_API bool operator!=(const CIdentifier& id1, const CIdentifier& id2);
|
||||
/**
|
||||
* \brief Ordering comparison operator
|
||||
* \param id1 [in] : The first identifier to compare
|
||||
* \param id2 [in] : The second identifier to compare
|
||||
* \return \e true when the first identifier is lesser or equal
|
||||
* to the second identifier, \e false in other cases.
|
||||
*
|
||||
* This function compares the two 64 bits values.
|
||||
*/
|
||||
friend EBML_API bool operator<=(const CIdentifier& id1, const CIdentifier& id2);
|
||||
/**
|
||||
* \brief Ordering comparison operator
|
||||
* \param id1 [in] : The first identifier to compare
|
||||
* \param id2 [in] : The second identifier to compare
|
||||
* \return \e true when the first identifier is greater or equal
|
||||
* to the second identifier, \e false in other cases.
|
||||
*
|
||||
* This function compares the two 64 bits values.
|
||||
*/
|
||||
friend EBML_API bool operator>=(const CIdentifier& id1, const CIdentifier& id2);
|
||||
/**
|
||||
* \brief Ordering comparison operator
|
||||
* \param id1 [in] : The first identifier to compare
|
||||
* \param id2 [in] : The second identifier to compare
|
||||
* \return \e true when the first identifier is lesser and not equal
|
||||
* to the second identifier, \e false in other cases.
|
||||
*
|
||||
* This function compares the two 64 bits values.
|
||||
*/
|
||||
friend EBML_API bool operator<(const CIdentifier& id1, const CIdentifier& id2);
|
||||
/**
|
||||
* \brief Ordering comparison operator
|
||||
* \param id1 [in] : The first identifier to compare
|
||||
* \param id2 [in] : The second identifier to compare
|
||||
* \return \e true when the first identifier is greater and not equal
|
||||
* to the second identifier, \e false in other cases.
|
||||
*
|
||||
* This function compares the two 64 bits values.
|
||||
*/
|
||||
friend EBML_API bool operator>(const CIdentifier& id1, const CIdentifier& id2);
|
||||
|
||||
/**
|
||||
* \brief Cast operator
|
||||
* \return \e the 64 bits value contained by this identifier.
|
||||
*/
|
||||
operator uint64_t() const { return this->id(); }
|
||||
|
||||
/**
|
||||
* \brief Conversion to 64 bits uint32_t (should be used instead of the cast)
|
||||
* \return \e the 64 bits value contained by this identifier.
|
||||
*/
|
||||
uint64_t id() const { return m_id; }
|
||||
|
||||
//@}
|
||||
|
||||
protected:
|
||||
|
||||
uint64_t m_id = 0; ///< The 64 bits value of this identifier
|
||||
};
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "IReader.h"
|
||||
|
||||
namespace EBML {
|
||||
class EBML_API CReader final : public IReader
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CReader(IReaderCallback& callback);
|
||||
~CReader() override;
|
||||
bool processData(const void* buffer, const size_t size) override;
|
||||
CIdentifier getCurrentNodeID() const override;
|
||||
size_t getCurrentNodeSize() const override;
|
||||
void release() override;
|
||||
|
||||
protected:
|
||||
|
||||
IReader* m_impl = nullptr;
|
||||
|
||||
private:
|
||||
|
||||
CReader() = delete;
|
||||
};
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "IReaderHelper.h"
|
||||
|
||||
namespace EBML {
|
||||
class EBML_API CReaderHelper final : public IReaderHelper
|
||||
{
|
||||
public:
|
||||
|
||||
CReaderHelper();
|
||||
~CReaderHelper() override;
|
||||
uint64_t getUInt(const void* buffer, const size_t size) override;
|
||||
int64_t getInt(const void* buffer, const size_t size) override;
|
||||
double getDouble(const void* buffer, const size_t size) override;
|
||||
const char* getStr(const void* buffer, const size_t size) override;
|
||||
void release() override;
|
||||
|
||||
protected:
|
||||
|
||||
IReaderHelper* m_impl = nullptr;
|
||||
};
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "IWriter.h"
|
||||
|
||||
namespace EBML {
|
||||
class EBML_API CWriter final : public IWriter
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CWriter(IWriterCallback& callback);
|
||||
~CWriter() override;
|
||||
bool openChild(const CIdentifier& identifier) override;
|
||||
bool setChildData(const void* buffer, const size_t size) override;
|
||||
bool closeChild() override;
|
||||
void release() override;
|
||||
|
||||
protected:
|
||||
|
||||
IWriter* m_impl = nullptr;
|
||||
|
||||
private:
|
||||
|
||||
CWriter() = delete;
|
||||
};
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "IWriterHelper.h"
|
||||
|
||||
namespace EBML {
|
||||
class EBML_API CWriterHelper final : public IWriterHelper
|
||||
{
|
||||
public:
|
||||
|
||||
CWriterHelper();
|
||||
~CWriterHelper() override;
|
||||
bool connect(IWriter* writer) override;
|
||||
bool disconnect() override;
|
||||
bool openChild(const CIdentifier& identifier) override;
|
||||
bool closeChild() override;
|
||||
bool setInt(const int64_t value) override;
|
||||
bool setUInt(const uint64_t value) override;
|
||||
bool setFloat(const float value) override;
|
||||
bool setDouble(const double value) override;
|
||||
bool setBinary(const void* buffer, const size_t size) override;
|
||||
bool setStr(const char* value) override;
|
||||
void release() override { }
|
||||
|
||||
protected:
|
||||
|
||||
IWriterHelper* m_impl = nullptr;
|
||||
};
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,135 @@
|
||||
#pragma once
|
||||
|
||||
#include "CIdentifier.h"
|
||||
#include <cstdlib> // fix Unix compatibility
|
||||
|
||||
namespace EBML {
|
||||
/**
|
||||
* \class IReaderCallback
|
||||
* \author Yann Renard (INRIA/IRISA)
|
||||
* \date 2006-08-07
|
||||
* \brief Callback class to use when parsing the EBML stream
|
||||
*
|
||||
* This class is to be overloaded by the user in order to get rid of the parsing events. It will be notified
|
||||
* by the EBML::IReader object of what is found in the stream.
|
||||
*
|
||||
* \sa EBML::IReader
|
||||
*/
|
||||
class EBML_API IReaderCallback
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~IReaderCallback() { }
|
||||
/**
|
||||
* \brief Kind of child querry
|
||||
* \param id [in] : The id which type has to be known
|
||||
* \return \e true when the node is a master node
|
||||
* \return \e false when it is a simple child node.
|
||||
*
|
||||
* When called by the reader, this function should tell it whether the node identified by \c id is a master
|
||||
* node (has child) or not (has data). For that, it has to return \e true when the node should have children, and \e false in other cases.
|
||||
*/
|
||||
virtual bool isMasterChild(const CIdentifier& id) = 0;
|
||||
/**
|
||||
* \brief Informs the callback object a new node parsing is starting
|
||||
* \param id [in] : The idenfier of the newly parsing node
|
||||
*
|
||||
* This is called to notify the callback object that the parser has started a new EBML node parsing. This EBML
|
||||
* node is identified by \c id. After this call will follow whether a new \c openChild if this node is
|
||||
* a master one, whher a processData if this node is a simple child one.
|
||||
*/
|
||||
virtual void openChild(const CIdentifier& id) = 0;
|
||||
/**
|
||||
* \brief Gives the callback object the data associated with the currently opened child node
|
||||
* \param buffer [in] : The buffer corresponding to the current simple child node
|
||||
* \param size [in] : The buffer size in bytes
|
||||
*
|
||||
* This function is called when the data reading is terminated for a simple child node and so the callback
|
||||
* object can process it. Whether the callback object knows how to process the data, whether it requests
|
||||
* a reader helper object to do the work... See EBML::IReaderHelper for more details on that subject.
|
||||
*/
|
||||
virtual void processChildData(const void* buffer, const size_t size) = 0;
|
||||
/**
|
||||
* \brief Informs the callback object the current node parsing is terminated
|
||||
*
|
||||
* This function tells the callback object the current node parsing is terminated. Thus the parsing continues for the
|
||||
* top level node, whether opening a new child or closing itself and so on...
|
||||
*/
|
||||
virtual void closeChild() = 0;
|
||||
};
|
||||
|
||||
class EBML_API IReaderCallBack : public IReaderCallback { };
|
||||
|
||||
/**
|
||||
* \class IReader
|
||||
* \author Yann Renard (INRIA/IRISA)
|
||||
* \date 2006-08-07
|
||||
* \brief EBML processing class
|
||||
*
|
||||
* This class should be used in order to parse an EBML stream. It should be given a callback object that can handle the
|
||||
* content of the stream. The parser itself as no understanding of what is included in the EBML structure.
|
||||
*
|
||||
* The parsing interface looks like the eXpat XML parser, allowing on-the-fly parsing. See http://expat.sourceforge.net for more details.
|
||||
*
|
||||
* To create instances of this class, the user has to call EBML::createReader. To delete instances of this class, the user has to call EBML::IReader::release.
|
||||
*
|
||||
* Be sure to look at http://ebml.sourceforge.net/specs/ in order to understand what EBML is and how it should be used.
|
||||
*/
|
||||
class EBML_API IReader
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \brief Processes a chunk of data
|
||||
* \param buffer [in] : The buffer of data to process
|
||||
* \param size [in] : The buffer size in bytes
|
||||
* \return \e true when data processing was ok
|
||||
* \return \e false in other cases.
|
||||
*
|
||||
* This function has to be called as soon as the stream reader (file, socket, whatever) has data. Those data
|
||||
* are sent to the parser and parsing for this chunk is started immediatly. The callback object is called
|
||||
* according to the EBML structure contained in the chunk and the previously parsed chunks. See
|
||||
* EBML::IReaderCallback for more details on the callback object.
|
||||
*/
|
||||
virtual bool processData(const void* buffer, const size_t size) = 0;
|
||||
/**
|
||||
* \brief Gets the identifier of the current node
|
||||
* \return the identifier of the current node
|
||||
*/
|
||||
virtual CIdentifier getCurrentNodeID() const = 0;
|
||||
/**
|
||||
* \brief Gets the size of the current node
|
||||
* \return the size of the current node
|
||||
*/
|
||||
virtual size_t getCurrentNodeSize() const = 0;
|
||||
/**
|
||||
* \brief Tells this object it won't be used anymore
|
||||
*
|
||||
* Instances of this class can not be instanciated another way than calling \c createReader. They can
|
||||
* not be deleted either because the destructor is. protected. The library knows how to create and
|
||||
* delete an instance of this class... Calling \c release will simply delete this instance and
|
||||
* handle necessary cleanings when needed.
|
||||
*
|
||||
* The current object is invalid after calling this function. It can not be used anymore.
|
||||
*/
|
||||
virtual void release() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* \brief Virtual destructor - should be overloaded
|
||||
*/
|
||||
virtual ~IReader() { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Instanciation function for EBML reader objects
|
||||
* \param callback [in] : The callback object the reader should use
|
||||
* \return a pointer to the created instance on success.
|
||||
* \return \c NULL when something went wrong.
|
||||
*/
|
||||
extern EBML_API IReader* createReader(IReaderCallback& callback);
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,93 @@
|
||||
#pragma once
|
||||
|
||||
#include "IReader.h"
|
||||
|
||||
namespace EBML {
|
||||
/**
|
||||
* \class IReaderHelper
|
||||
* \author Yann Renard (INRIA/IRISA)
|
||||
* \date 2006-08-07
|
||||
* \brief Helper to read basic EBML types
|
||||
*
|
||||
* This class may be used by a IReaderCallback instance
|
||||
* in order to correctly parse simple types defined in the
|
||||
* EBML description such as integers, floats, strings etc...
|
||||
*
|
||||
* A similar class exists to help formating process...
|
||||
* See EBML::IWriterHelper for more details.
|
||||
*
|
||||
* Be sure to look at http://ebml.sourceforge.net/specs/ in
|
||||
* order to understand what EBML is and how it should be used.
|
||||
*
|
||||
* \todo long double reading implementation
|
||||
* \todo date reading implementation
|
||||
* \todo utf8 string reading implementation
|
||||
*/
|
||||
class EBML_API IReaderHelper
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \name Standard EBML value reading
|
||||
* \param buffer [in] : The buffer containing data
|
||||
* \param size [in] : The buffer size in bytes
|
||||
* \return The value contained in the buffer
|
||||
*
|
||||
* Be sure to look at http://ebml.sourceforge.net/specs/ in
|
||||
* order to understand standard EBML types.
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* \brief Gets an unsigned integer from the given buffer
|
||||
*/
|
||||
virtual uint64_t getUInt(const void* buffer, const size_t size) = 0;
|
||||
/**
|
||||
* \brief Gets a signed integer from the given buffer
|
||||
*/
|
||||
virtual int64_t getInt(const void* buffer, const size_t size) = 0;
|
||||
/**
|
||||
* \brief Gets a float from the given buffer
|
||||
*/
|
||||
virtual double getDouble(const void* buffer, const size_t size) = 0;
|
||||
// virtual ??? getFloat80FromChildData(const void* buffer, const size_t size)=0;
|
||||
// virtual ??? getDateFromChildData(const void* buffer, const size_t size)=0;
|
||||
/**
|
||||
* \brief Gets an ASCII string from the given buffer
|
||||
* \warning The returned value is not permanent. It should be
|
||||
* copied immediatly somewhere else by the caller.
|
||||
*/
|
||||
virtual const char* getStr(const void* buffer, const size_t size) = 0;
|
||||
// virtual ??? getUTF8StringFromChildData(const void* buffer, const size_t size)=0;
|
||||
//@}
|
||||
|
||||
/**
|
||||
* \brief Tells this object it won't be used anymore
|
||||
*
|
||||
* Instances of this class can not be instanciated
|
||||
* another way than calling \c createReaderHelper. They
|
||||
* can not be deleted either because the destructor is.
|
||||
* protected. The library knows how to create and
|
||||
* delete an instance of this class... Calling
|
||||
* \c release will simply delete this instance and
|
||||
* handle necessary cleanings when needed.
|
||||
*
|
||||
* The current object is invalid after calling this
|
||||
* function. It can not be used anymore.
|
||||
*/
|
||||
virtual void release() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* \brief Virtual destructor - should be overloaded
|
||||
*/
|
||||
virtual ~IReaderHelper() { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Instanciation function for EBML reader helper objects
|
||||
* \return a pointer to the created instance on success.
|
||||
* \return \c NULL when something went wrong.
|
||||
*/
|
||||
extern EBML_API IReaderHelper* createReaderHelper();
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include "CIdentifier.h"
|
||||
#include <cstdlib> // fix Unix compatibility
|
||||
|
||||
namespace EBML {
|
||||
/**
|
||||
* \class IWriterCallback
|
||||
* \author Yann Renard (INRIA/IRISA)
|
||||
* \date 2006-08-07
|
||||
* \brief Callback class to use when creating the EBML stream
|
||||
*
|
||||
* This class is to be overloaded by the user in order to get rid of the stream writing events. It will be
|
||||
* notified by the EBML::IWriter object of what is to be written in the stream while the user sends information to the writer.
|
||||
*
|
||||
* \sa EBML::IWriter
|
||||
*/
|
||||
class EBML_API IWriterCallback
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~IWriterCallback() { }
|
||||
/**
|
||||
* \brief Gives the callback object a new stream chunk
|
||||
* \param buffer [in] : The buffer to write in the stream
|
||||
* \param size [in] : The buffer size in bytes
|
||||
*
|
||||
* This function tells the callback object new data are ready to send in the EBML stream. This function
|
||||
* may be called while the user sends data to the writer.
|
||||
*/
|
||||
virtual void write(const void* buffer, const size_t size) = 0;
|
||||
};
|
||||
|
||||
class EBML_API IWriterCallBack : public IWriterCallback { };
|
||||
|
||||
/**
|
||||
* \class IWriter
|
||||
* \author Yann Renard (INRIA/IRISA)
|
||||
* \date 2006-08-07
|
||||
* \brief EBML formating class
|
||||
*
|
||||
* This class is used in order to format datas using EBML specifications. It gives a minimalistic interface to
|
||||
* allow creating new EBML nodes, and to insert data in simple child nodes.
|
||||
*
|
||||
* Basic usage of this class consists in :
|
||||
*
|
||||
* - Create child node
|
||||
* - Gives information about the node :
|
||||
* - Whether created node is master node (Goto 1)
|
||||
* - Whether created node is simple child node (set data for this child node)
|
||||
* - Close opened node
|
||||
*
|
||||
* The EBML::IWriterHelper class could be used in order to send EBML standard data such as integers, floats, strings, etc...
|
||||
*
|
||||
* To create instances of this class, the user has to call EBML::createWriter. To delete instances of this class, the user has to call EBML::IWriter::release.
|
||||
*
|
||||
* Be sure to look at http://ebml.sourceforge.net/specs/ in order to understand what EBML is and how it should be used.
|
||||
*/
|
||||
class EBML_API IWriter
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \brief Starts a new child node
|
||||
* \param identifier [in] : The identifier of the new child node
|
||||
* \return \e true on success.
|
||||
* \return \e false on error.
|
||||
*
|
||||
* This function is called when the user wants to add a child node to the currently opened master node.
|
||||
* A node containing data can not have child so if \c setChildData has been called before, this function returns \e false.
|
||||
*
|
||||
* Once the node has been opened, it should be closed calling \c closeChild.
|
||||
*/
|
||||
virtual bool openChild(const CIdentifier& identifier) = 0;
|
||||
/**
|
||||
* \brief Sets data for simple child node
|
||||
* \param buffer [in] : The buffer to set as child data
|
||||
* \param size [in] : The buffer size in bytes
|
||||
* \return \e true on success.
|
||||
* \return \e false on error.
|
||||
*
|
||||
* This function is called by the user for setting data in the currently opened simple child node.
|
||||
* If the currently opened node has children, it is a master node so it can't receive data. In such case, the function returns \e false. However,
|
||||
* it the currently opened node already has data, it returns \e false too.
|
||||
*/
|
||||
virtual bool setChildData(const void* buffer, const size_t size) = 0;
|
||||
/**
|
||||
* \brief Closes currently opened child node
|
||||
* \return \e true on success.
|
||||
* \return \e false on error.
|
||||
*
|
||||
* This function is called when the user wants to close a child node. The node should have received
|
||||
* either child nodes or data depending if it is a master node or a simple child node.
|
||||
*/
|
||||
virtual bool closeChild() = 0;
|
||||
/**
|
||||
* \brief Tells this object it won't be used anymore
|
||||
*
|
||||
* Instances of this class can not be instanciated another way than calling \c createWriter. They can
|
||||
* not be deleted either because the destructor is. protected. The library knows how to create and
|
||||
* delete an instance of this class... Calling \c release will simply delete this instance and
|
||||
* handle necessary cleanings when needed.
|
||||
*
|
||||
* The current object is invalid after calling this
|
||||
* function. It can not be used anymore.
|
||||
*/
|
||||
virtual void release() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* \brief Virtual destructor - should be overloaded
|
||||
*/
|
||||
virtual ~IWriter() { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Instanciation function for EBML writer objects
|
||||
* \param callback [in] : The callback object the writer should use
|
||||
* \return a pointer to the created instance on success.
|
||||
* \return \c NULL when something went wrong.
|
||||
*/
|
||||
extern EBML_API IWriter* createWriter(IWriterCallback& callback);
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,176 @@
|
||||
#pragma once
|
||||
|
||||
#include "IWriter.h"
|
||||
|
||||
namespace EBML {
|
||||
/**
|
||||
* \class IWriterHelper
|
||||
* \author Yann Renard (INRIA/IRISA)
|
||||
* \date 2006-08-07
|
||||
* \brief Helper to write basic EBML types
|
||||
*
|
||||
* This class may be used by the user in order to correctly
|
||||
* format simple types defined in the EBML description such
|
||||
* as integers, floats, strings etc... It directly uses the
|
||||
* EBML::IWriter connected instance so one could simply
|
||||
* use the helper in order to write his EBML stream.
|
||||
*
|
||||
* A similar class exists to help parsing process...
|
||||
* See EBML::IReaderHelper for more details.
|
||||
*
|
||||
* Be sure to look at http://ebml.sourceforge.net/specs/ in
|
||||
* order to understand what EBML is and how it should be used.
|
||||
*
|
||||
* \todo long double formating implementation
|
||||
* \todo date formating implementation
|
||||
* \todo utf8 string formating implementation
|
||||
*/
|
||||
class EBML_API IWriterHelper
|
||||
{
|
||||
public:
|
||||
|
||||
/** \name Writer connection */
|
||||
//@{
|
||||
/**
|
||||
* \brief Connects an EBML writer to this helper
|
||||
* \param writer [in] : The writer to connect
|
||||
* \return \e true on success.
|
||||
* \return \e false on error.
|
||||
*
|
||||
* This function gives the helper a handle to the writer
|
||||
* to use in order to forward requests. Thus, when the
|
||||
* user calls a helper function, the call is forwarded
|
||||
* to the correct writer that effictively does the work.
|
||||
* The aim of this helper is simply to transform standard
|
||||
* EBML types into bytes buffers.
|
||||
*
|
||||
* Once a writer is connected, it could be disconnected
|
||||
* thanks to the \c disconnect function. It must be done
|
||||
* before calling \c connect again.
|
||||
*/
|
||||
virtual bool connect(IWriter* writer) = 0;
|
||||
/**
|
||||
* \brief Disconnects the currently connected EBML writer
|
||||
* \return \e true on success.
|
||||
* \return \e false on error.
|
||||
*
|
||||
* This function should be called to release the EBML
|
||||
* writer handle. The helper instance may then be used
|
||||
* with another EBML writer instance calling \c connect
|
||||
* again.
|
||||
*/
|
||||
virtual bool disconnect() = 0;
|
||||
//@}
|
||||
|
||||
/** \name Writer binding functions */
|
||||
//@{
|
||||
/**
|
||||
* \brief Child opening binding
|
||||
* \param identifier [in] : The identifier of the new child node
|
||||
* \return \e true on success.
|
||||
* \return \e false on error.
|
||||
*
|
||||
* This function simply forwards the call to the
|
||||
* corresponding EBML::IWriter function. See
|
||||
* EBML::IWriter::openChild for more details.
|
||||
*/
|
||||
virtual bool openChild(const CIdentifier& identifier) = 0;
|
||||
/**
|
||||
* \brief Child closing binding
|
||||
* \return \e true on success.
|
||||
* \return \e false on error.
|
||||
*
|
||||
* This function simply forwards the call to the
|
||||
* corresponding EBML::IWriter function. See
|
||||
* EBML::IWriter::closeChild for more details.
|
||||
*/
|
||||
virtual bool closeChild() = 0;
|
||||
//@}
|
||||
|
||||
/**
|
||||
* \name Standard EBML formating
|
||||
* \brief EBML::IWriter::setChildData replacement
|
||||
* \return \e true on success.
|
||||
* \return \e false on error.
|
||||
*
|
||||
* Those functions should be used in place of the
|
||||
* basic EBML::IWriter::setChildData function. They
|
||||
* format standard EBML types into corresponding
|
||||
* buffers and then send those built buffers to
|
||||
* the writer using the EBML::IWriter::setChildData
|
||||
* function.
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* \brief Sets a signed integer as child data
|
||||
* \param value [in] : The integer value to set
|
||||
*/
|
||||
virtual bool setInt(const int64_t value) = 0;
|
||||
/**
|
||||
* \brief Sets an unsigned integer as child data
|
||||
* \param value [in] : The integer value to set
|
||||
*/
|
||||
virtual bool setUInt(const uint64_t value) = 0;
|
||||
/**
|
||||
* \brief Sets a 32 bits float value as child data
|
||||
* \param value [in] : The 32 bits float value to set
|
||||
*/
|
||||
virtual bool setFloat(const float value) = 0;
|
||||
/**
|
||||
* \brief Sets a 64 bits float value as child data
|
||||
* \param value [in] : The 64 bits float value to set
|
||||
*/
|
||||
virtual bool setDouble(const double value) = 0;
|
||||
// virtual bool setFloat80AsChildData( ??? value)=0;
|
||||
// virtual bool setDateAsChildData( ??? value)=0;
|
||||
/**
|
||||
* \brief Sets a buffer as child data
|
||||
* \param buffer [in] : The buffer to send to the writer
|
||||
* \param size [in] : The buffer size in bytes
|
||||
* \note This function simply calls the basic
|
||||
* EBML::IWriter::setChildData function with the
|
||||
* same two parameters.
|
||||
*/
|
||||
virtual bool setBinary(const void* buffer, const size_t size) = 0;
|
||||
/**
|
||||
* \brief Sets an ASCII string as child data
|
||||
* \param value [in] : The ASCII string value to set
|
||||
*/
|
||||
virtual bool setStr(const char* value) = 0;
|
||||
// virtual bool setUTF8StringAsChildData( ??? value)=0;
|
||||
//@}
|
||||
|
||||
/**
|
||||
* \brief Tells this object it won't be used anymore
|
||||
*
|
||||
* Instances of this class can not be instanciated
|
||||
* another way than calling \c createWriterHelper. They
|
||||
* can not be deleted either because the destructor is.
|
||||
* protected. The library knows how to create and
|
||||
* delete an instance of this class... Calling
|
||||
* \c release will simply delete this instance and
|
||||
* handle necessary cleanings when needed.
|
||||
*
|
||||
* The current object is invalid after calling this
|
||||
* function. It can not be used anymore.
|
||||
*
|
||||
* \warning Releasing this obbject does not release the
|
||||
* connected writer instance !
|
||||
*/
|
||||
virtual void release() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* \brief Virtual destructor - should be overloaded
|
||||
*/
|
||||
virtual ~IWriterHelper() { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Instanciation function for EBML writer helper objects
|
||||
* \return a pointer to the created instance on success.
|
||||
* \return \c NULL when something went wrong.
|
||||
*/
|
||||
extern EBML_API IWriterHelper* createWriterHelper();
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include "IReader.h"
|
||||
|
||||
namespace EBML {
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
template <class TOwnerClass>
|
||||
class TReaderCallbackProxy1 final : public IReaderCallback
|
||||
{
|
||||
public:
|
||||
TReaderCallbackProxy1(TOwnerClass& ownerObject, bool (TOwnerClass::*mfpIsMasterChild)(const CIdentifier& identifier),
|
||||
void (TOwnerClass::*mfpOpenChild)(const CIdentifier& identifier),
|
||||
void (TOwnerClass::*mfpProcessChildData)(const void* buffer, const size_t size), void (TOwnerClass::*mfpCloseChild)())
|
||||
: m_ownerObject(ownerObject), m_mfpIsMasterChild(mfpIsMasterChild), m_mfpOpenChild(mfpOpenChild), m_mfpProcessChildData(mfpProcessChildData),
|
||||
m_mfpCloseChild(mfpCloseChild) { }
|
||||
|
||||
bool isMasterChild(const CIdentifier& identifier) override
|
||||
{
|
||||
if (m_mfpIsMasterChild) { return (m_ownerObject.*m_mfpIsMasterChild)(identifier); }
|
||||
return false;
|
||||
}
|
||||
|
||||
void openChild(const CIdentifier& identifier) override { if (m_mfpOpenChild) { (m_ownerObject.*m_mfpOpenChild)(identifier); } }
|
||||
|
||||
void processChildData(const void* buffer, const size_t size) override
|
||||
{
|
||||
if (m_mfpProcessChildData) { (m_ownerObject.*m_mfpProcessChildData)(buffer, size); }
|
||||
}
|
||||
|
||||
void closeChild() override { if (m_mfpCloseChild) { (m_ownerObject.*m_mfpCloseChild)(); } }
|
||||
|
||||
protected:
|
||||
TOwnerClass& m_ownerObject;
|
||||
bool (TOwnerClass::*m_mfpIsMasterChild)(const CIdentifier& identifier);
|
||||
void (TOwnerClass::*m_mfpOpenChild)(const CIdentifier& identifier);
|
||||
void (TOwnerClass::*m_mfpProcessChildData)(const void* buffer, size_t size);
|
||||
void (TOwnerClass::*m_mfpCloseChild)();
|
||||
};
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
template <class TOwnerClass, bool (TOwnerClass::*TMfpIsMasterChild)(const CIdentifier& identifier),
|
||||
void (TOwnerClass::*TMfpOpenChild)(const CIdentifier& identifier),
|
||||
void (TOwnerClass::*TMfpProcessChildData)(const void* buffer, size_t size), void (TOwnerClass::*TMfpCloseChild)()>
|
||||
class TReaderCallbackProxy2 final : public IReaderCallback
|
||||
{
|
||||
public:
|
||||
TReaderCallbackProxy2(TOwnerClass& ownerObject)
|
||||
: m_ownerObject(ownerObject), m_mfpIsMasterChild(TMfpIsMasterChild), m_mfpOpenChild(TMfpOpenChild), m_mfpProcessChildData(TMfpProcessChildData),
|
||||
m_mfpCloseChild(TMfpCloseChild) { }
|
||||
|
||||
bool isMasterChild(const CIdentifier& identifier) override
|
||||
{
|
||||
if (m_mfpIsMasterChild) { return (m_ownerObject.*m_mfpIsMasterChild)(identifier); }
|
||||
return false;
|
||||
}
|
||||
|
||||
void openChild(const CIdentifier& identifier) override { if (m_mfpOpenChild) { (m_ownerObject.*m_mfpOpenChild)(identifier); } }
|
||||
|
||||
void processChildData(const void* buffer, const size_t size) override
|
||||
{
|
||||
if (m_mfpProcessChildData) { (m_ownerObject.*m_mfpProcessChildData)(buffer, size); }
|
||||
}
|
||||
|
||||
void closeChild() override { if (m_mfpCloseChild) { (m_ownerObject.*m_mfpCloseChild)(); } }
|
||||
|
||||
protected:
|
||||
TOwnerClass& m_ownerObject;
|
||||
bool (TOwnerClass::*m_mfpIsMasterChild)(const CIdentifier& identifier);
|
||||
void (TOwnerClass::*m_mfpOpenChild)(const CIdentifier& identifier);
|
||||
void (TOwnerClass::*m_mfpProcessChildData)(const void* buffer, size_t size);
|
||||
void (TOwnerClass::*m_mfpCloseChild)();
|
||||
};
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "IWriter.h"
|
||||
|
||||
namespace EBML {
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
template <class TOwnerClass>
|
||||
class TWriterCallbackProxy1 final : public IWriterCallback
|
||||
{
|
||||
public:
|
||||
TWriterCallbackProxy1(TOwnerClass& ownerObject, void (TOwnerClass::*mfpWrite)(const void* buffer, size_t size))
|
||||
: m_ownerObject(ownerObject), m_mfpWrite(mfpWrite) { }
|
||||
|
||||
void write(const void* buffer, const size_t size) override { if (m_mfpWrite) { (m_ownerObject.*m_mfpWrite)(buffer, size); } }
|
||||
|
||||
protected:
|
||||
TOwnerClass& m_ownerObject;
|
||||
void (TOwnerClass::*m_mfpWrite)(const void* buffer, size_t size);
|
||||
};
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
|
||||
template <class TOwnerClass, void (TOwnerClass::*TMfpWrite)(const void* buffer, size_t size)>
|
||||
class TWriterCallbackProxy2 final : public IWriterCallback
|
||||
{
|
||||
public:
|
||||
TWriterCallbackProxy2(TOwnerClass& ownerObject) : m_ownerObject(ownerObject), m_mfpWrite(TMfpWrite) { }
|
||||
|
||||
void write(const void* buffer, const size_t size) override { if (m_mfpWrite) { (m_ownerObject.*m_mfpWrite)(buffer, size); } }
|
||||
|
||||
protected:
|
||||
TOwnerClass& m_ownerObject;
|
||||
void (TOwnerClass::*m_mfpWrite)(const void* buffer, size_t size);
|
||||
};
|
||||
|
||||
// ________________________________________________________________________________________________________________
|
||||
//
|
||||
} // namespace EBML
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* \file defines.h
|
||||
* \author Yann Renard (INRIA/IRISA)
|
||||
* \date 2006-08-07
|
||||
* \brief Contains basic type definitions and EBML standard identifiers
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ov_common_defines.h>
|
||||
#include <cstdlib> // For Unix Compatibility
|
||||
#include <cstdint>
|
||||
|
||||
//___________________________________________________________________//
|
||||
// //
|
||||
// EBML Standard identifiers definitions //
|
||||
//___________________________________________________________________//
|
||||
// //
|
||||
|
||||
/**
|
||||
* \name EBML standard identifiers definitions
|
||||
*
|
||||
* Be sure to look at http://ebml.sourceforge.net/specs/ to
|
||||
* have more information on EBML and its standard identifiers.
|
||||
*/
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* EBML Header.
|
||||
* This is a master node.
|
||||
* It contains several information about the ebml stream.
|
||||
*/
|
||||
#define EBML_Identifier_Header EBML::CIdentifier(0x0A45DFA3)
|
||||
/**
|
||||
* EBML Version.
|
||||
* This is a child node of type \c integer.
|
||||
* It contains the EBML version.
|
||||
*/
|
||||
#define EBML_Identifier_EBMLVersion EBML::CIdentifier(0x0286)
|
||||
/**
|
||||
* EBML Read Version.
|
||||
* This is a child node of type \c integer.
|
||||
* Indicates the EBML version a parser has to support to read this file
|
||||
*/
|
||||
#define EBML_Identifier_EBMLReadVersion EBML::CIdentifier(0x02F7)
|
||||
/**
|
||||
* EBML Identifier Length.
|
||||
* This is a child node of type \c integer.
|
||||
* Indicates the parser the maximum number of bytes an identifier
|
||||
* can have.
|
||||
*/
|
||||
#define EBML_Identifier_EBMLIdLength EBML::CIdentifier(0x02F2)
|
||||
/**
|
||||
* EBML Size Length.
|
||||
* This is a child node of type \c integer.
|
||||
* Indicates the paser the maximum number of bytes a node
|
||||
* can have.
|
||||
*/
|
||||
#define EBML_Identifier_EBMLSizeLength EBML::CIdentifier(0x02F3)
|
||||
/**
|
||||
* EBML Document Type.
|
||||
* This is a child node of type \c string.
|
||||
* Indicates the parser the kind of document being parsed.
|
||||
*/
|
||||
#define EBML_Identifier_DocType EBML::CIdentifier(0x0282)
|
||||
/**
|
||||
* EBML Document Type Version.
|
||||
* This is a child node of type \c integer.
|
||||
* Indicates the parser the specification version of the document
|
||||
* being parsed.
|
||||
*/
|
||||
#define EBML_Identifier_DocTypeVersion EBML::CIdentifier(0x0287)
|
||||
/**
|
||||
* EBML Document Type Read Version.
|
||||
* This is a child node of type \c integer.
|
||||
* Indicates the parser the version of the reader to use in order
|
||||
* to understand the document content.
|
||||
*/
|
||||
#define EBML_Identifier_DocTypeReadVersion EBML::CIdentifier(0x0285)
|
||||
/**
|
||||
* EBML Void.
|
||||
* This is a child node of type \c binary.
|
||||
* Indicates an ununderstandable chunk of data to skip.
|
||||
*/
|
||||
#define EBML_Identifier_Void EBML::CIdentifier(0x6C)
|
||||
/**
|
||||
* EBML CRC32.
|
||||
* This is a child node of type \c binary.
|
||||
* This is a CRC32 checksum of the content between this CRC32
|
||||
* and the last one.
|
||||
*/
|
||||
#define EBML_Identifier_CRC32 EBML::CIdentifier(0x02FE)
|
||||
|
||||
//@}
|
||||
|
||||
#if defined EBML_Shared
|
||||
# if defined TARGET_OS_Windows
|
||||
# define EBML_API_Export __declspec(dllexport)
|
||||
# define EBML_API_Import __declspec(dllimport)
|
||||
# elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
# define EBML_API_Export __attribute__((visibility("default")))
|
||||
# define EBML_API_Import __attribute__((visibility("default")))
|
||||
# else
|
||||
# define EBML_API_Export
|
||||
# define EBML_API_Import
|
||||
# endif
|
||||
#else
|
||||
# define EBML_API_Export
|
||||
# define EBML_API_Import
|
||||
#endif
|
||||
|
||||
#if defined EBML_Exports
|
||||
# define EBML_API EBML_API_Export
|
||||
#else
|
||||
# define EBML_API EBML_API_Import
|
||||
#endif
|
||||
Reference in New Issue
Block a user