//
// Irrlicht Wrapper for Imperative Languages
// Frank Dodd (2006)
//
// Additional Work
// Michael Taupitz (2006)
//
// This wrapper DLL encapsulates a sub-set of the features of the powerful
// Irrlicht 3D Graphics Engine exposing the Object Oriented architecture and
// providing a functional 3D SDK for languages that are not object oriented.
//
// This source was created with the help of the great examples in the Irrlicht
// SDK and the excellent Irrlicht documentation. This software was developed
// using the GCC compiler and Code::Blocks IDE
//

/* ////////////////////////////////////////////////////////////////////////////
includes
*/
#include "irrlichtwrapper.h"


/* ////////////////////////////////////////////////////////////////////////////
global variables
*/

/* ////////////////////////////////////////////////////////////////////////////
external variables
*/
extern IrrlichtDevice *device;
extern IVideoDriver* driver;
extern ISceneManager* smgr;
extern IGUIEnvironment* guienv;


/* ////////////////////////////////////////////////////////////////////////////
Global Function Declarations

all of the below functions are declared as C functions and are exposed without
any mangled names so that they can be easily imported into imperative
languages like FreeBasic
*/
extern "C"
{

/* ////////////////////////////////////////////////////////////////////////////
XML FUNCTIONS
*/
/****f* XML/IrrXmlCreateReader
* NAME
*    IrrXmlCreateReader - Creates a XML Reader from a file
* SYNOPSIS
*    IrrXmlCreateReader(filename.s)
* INPUTS
*   filename.s      -   name of the xml file
* FUNCTION
*   Creates a XML Reader from a file.
* RESULT
*    #Null if no Reader created, otherwise the pointer to the XML-Reader.
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlCreateReader(filename.p-ascii)
*/

STATIC_EXPORT void* DLL_EXPORT IrrXmlCreateReader( char *cptrFile )
{
    return device->getFileSystem()->createXMLReader(cptrFile);
}

/****f* XML/IrrXmlFreeReader
* NAME
*    IrrXmlFreeReader - Frees a XML-Reader
* SYNOPSIS
*    IrrXmlFreeReader(*xmlreader.l)
* INPUTS
*   *xmlreader.l     -   pointer to a xml reader
* FUNCTION
*   Frees / destroys a Xml-Reader, thet was created before with IrrXmlCreateReader()
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlFreeReader(*xmlreader.l)
*/
STATIC_EXPORT void DLL_EXPORT IrrXmlFreeReader( io::IXMLReader* xml )
{
    delete xml;
}

/****f* XML/IrrXmlRead
* NAME
*    IrrXmlRead - Read next xml-entry
* SYNOPSIS
*    IrrXmlRead(*xmlreader.l)
* INPUTS
*   *xmlreader.l     -   pointer to a xml reader
* FUNCTION
*   Reads forward to the next xml node.
* RESULT
*    Return #False, if there was no further node.
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlRead(*xmlreader.l)
*/
STATIC_EXPORT bool DLL_EXPORT IrrXmlRead(io::IXMLReader* xml)
{
    return xml->read();
}

/****f* XML/IrrXmlGetAttributeCount
* NAME
*    IrrXmlGetAttributeCount - retrieves the Attribute-count
* SYNOPSIS
*    IrrXmlGetAttributeCount(*xmlreader.l)
* INPUTS
*   *xmlreader.l     -   pointer to a xml reader
* FUNCTION
*   Returns the number of Attributes for the current XML-Node.
*   This is usually non #NULL if the current node is #IRR_EXN_ELEMENT,
*   and the element has attributes
* RESULT
*    amount of attributes
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlGetAttributeCount(*xmlreader.l)
*/

STATIC_EXPORT int DLL_EXPORT IrrXmlGetAttributeCount(io::IXMLReader* xml)
{
    return xml->getAttributeCount();
}

/****f* XML/IrrXmlGetAttributeName
* NAME
*    IrrXmlGetAttributeName - retrieves the Attribute-name
* SYNOPSIS
*    IrrXmlGetAttributeName(*xmlreader.l, index.l)
* INPUTS
*   *xmlreader.l     -  pointer to a xml-reader
*   index.l          -  Zero based index, should be something between 0 and IrrXmlGetAttributeCount() minus 1.
* FUNCTION
*   Returns name of an attribute.
* EXAMPLE
*   ;since it was a little bit tricky to get strings, you need here a PokeS()
*   nodeName.s = PeekS(IrrXmlGetNodeName(*xml,1),#PB_Unicode)
* RESULT
*    pointer to a Unicode-String.
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlGetAttributeName(*xmlreader.l, index.l)
*/
STATIC_EXPORT const wchar_t* DLL_EXPORT IrrXmlGetAttributeName(io::IXMLReader* xml, int idx)
{
    return xml->getAttributeName(idx);
}

/****f* XML/IrrXmlGetAttributeValue
* NAME
*    IrrXmlGetAttributeValue - retrieves the Attribute-value
* SYNOPSIS
*    IrrXmlGetAttributeValue(*xmlreader.l, index.l)
* INPUTS
*   *xmlreader.l     -  pointer to a xml reader
*   index.l          -  Zero based index, should be something between 0 and IrrXmlGetAttributeCount() minus 1.
* FUNCTION
*   Returns value of an attribute as String (Unicode !)
* EXAMPLE
*   ;since it was a little bit tricky to get strings, you need here a PeekS()
*   nodeValue.s = PeekS(IrrXmlGetAttributeValue(*xml,1),#PB_Unicode)
* RESULT
*    pointer to a Unicode-String.
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlGetAttributeValue(*xmlreader.l, index.l)
*/
STATIC_EXPORT const wchar_t* DLL_EXPORT IrrXmlGetAttributeValue(io::IXMLReader* xml, int idx)
{
    return xml->getAttributeValue(idx);
}

/****f* XML/IrrXmlGetAttributeValueByName
* NAME
*    IrrXmlGetAttributeValueByName - retrieves the Attribute-value
* SYNOPSIS
*    IrrXmlGetAttributeValueByName(*xmlreader.l, attributeName.s)
* INPUTS
*   *xmlreader.l     -  pointer to a xml reader
*   attributeName.s  -  Name of the Attribut to retrieve
* FUNCTION
*   Returns value of an attribute as String (Unicode !)
* EXAMPLE
*   ;since it was a little bit tricky to get strings, you need here a PeekS()
*   nodeValue.s = PeekS(IrrXmlGetAttributeValueByName(*xml,"class"),#PB_Unicode)
* RESULT
*    pointer to a Unicode-String.
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlGetAttributeValueByName(*xmlreader.l, attributeName.p-unicode)
*/
STATIC_EXPORT const wchar_t* DLL_EXPORT IrrXmlGetAttributeValueByName(io::IXMLReader* xml, const wchar_t* name)
{
    return xml->getAttributeValue(name);
}

/****f* XML/IrrXmlGetNodeName
* NAME
*    IrrXmlGetNodeName - retrieves the Node-Name
* SYNOPSIS
*    IrrXmlGetNodeName(*xmlreader.l)
* INPUTS
*   *xmlreader.l     -  pointer to a xml reader
* FUNCTION
*   Returns of a Node as String (Unicode !)
* EXAMPLE
*   ;since it was a little bit tricky to get strings, you need here a PeekS()
*   nodeName.s = PeekS(IrrXmlGetNodeName(*xml)
* RESULT
*    pointer to a Unicode-String.
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlGetNodeName(*xmlreader.l)
*/
STATIC_EXPORT const wchar_t* DLL_EXPORT IrrXmlGetNodeName(io::IXMLReader* xml)
{
    return xml->getNodeName();
}

/****f* XML/IrrXmlGetNodeData
* NAME
*    IrrXmlGetNodeData - retrieves the Node-Data
* SYNOPSIS
*    IrrXmlGetNodeData(*xmlreader.l)
* INPUTS
*   *xmlreader.l     -  pointer to a xml reader
* FUNCTION
*   Returns data of the current node.
*   Only non #NULL if the node has some data and it is of type #IRR_EXN_TEXT or #IRR_EXN_UNKNOWN
* EXAMPLE
*   ;since it was a little bit tricky to get strings, you need here a PeekS()
*   nodeData.s = PeekS(IrrXmlGetNodeData(*xml)
* RESULT
*    pointer to a Unicode-String.
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlGetNodeData(*xmlreader.l)
*/
STATIC_EXPORT const wchar_t* DLL_EXPORT IrrXmlGetNodeData(io::IXMLReader* xml)
{
    return xml->getNodeData();
}

/****f* XML/IrrXmlGetNodeType
* NAME
*    IrrXmlGetNodeType - retrieves the Node-Type
* SYNOPSIS
*    IrrXmlGetNodeType(*xmlreader.l)
* INPUTS
*   *xmlreader.l     -  pointer to a xml reader
* FUNCTION
*   Returns the type of the current XML node.
* EXAMPLE
*   nodeType.l = IrrXmlGetNodeType(*xml)
* RESULT
*    Enum as Type of the Node
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlGetNodeType(*xmlreader.l)
*/
STATIC_EXPORT EXML_NODE DLL_EXPORT IrrXmlGetNodeType(io::IXMLReader* xml)
{
    return xml->getNodeType();
}


/****f* XML/IrrXmlIsEmptyElement
* NAME
*    IrrXmlIsEmptyElement - checks if this Element is Empty
* SYNOPSIS
*    result.l = IrrXmlIsEmptyElement(*xmlreader.l)
* INPUTS
*   *xmlreader.l     -  pointer to a xml reader
* FUNCTION
*   Returns #True if the Element is Empty
* EXAMPLE
*   isEmpty.l = IrrXmlIsEmptyElement(*xml)
* RESULT
*   #True if Element is empty, otherwise #False
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrXmlIsEmptyElement(*xmlreader.l)
*/

STATIC_EXPORT bool DLL_EXPORT IrrXmlIsEmptyElement(io::IXMLReader* xml)
{
    return xml->isEmptyElement();
}


/* ////////////////////////////////////////////////////////////////////////////
all of the above functions are declared as C functions and are exposed without
any mangled names
*/
}
