/* --------------------------------------------------------------------------
 *	ScriptEngine
 * --------------------------------------------------------------------------
 *	
 *	Embedded Python Script Engine
 *
 * --------------------------------------------------------------------------
 *	
 *	prog:	max rheiner / max.rheiner@zhdk.ch
 *	date:	9/2/2007	(m/d/y)
 *
 * ----------------------------------------------------------------------------
 */

#ifndef SCRIPTENGINE_HXX
#define SCRIPTENGINE_HXX

#include <string>
#include <vector>
#undef check
#include <boost/python.hpp>

namespace scriptEngine{

///////////////////////////////////////////////////////////////////////////////
// ret types

typedef std::vector<int>			IntList;
typedef std::vector<float>			FloatList;
typedef std::vector<std::string>	StringList;

///////////////////////////////////////////////////////////////////////////////
// init functions

/*! \brief Startup the script environment
 *
 *  This command has to be called at the beginning of the use of the scriptEngine
 */
void Start();

/*! \brief Close the script environment
 *
 *  This command has to be called at the end of the use of the scriptEngine
 */
void End();

///////////////////////////////////////////////////////////////////////////////
// context functions

/*! \fn PyObject* GetMainDict()
	\brief Returns the main dictionary
    \return main dictionary
 */
PyObject* GetMainDict();

///////////////////////////////////////////////////////////////////////////////
// script load functions

/*! \fn bool Load(const std::string& file)
	\brief Loads a python script into the embedded interpreter
    \param file a string with the file path
    \return True if succesfull
 */
bool Load(const std::string& file);

///////////////////////////////////////////////////////////////////////////////
// script access

/*! \fn bool Run(const std::string& code)
	\brief Runs the string in the embedded python environment
    \param code a string with the pytho code
 */
void Run(const std::string& code);

/*! \fn bool readFloat(PyObject* obj,float defValue=0.0f)
	\brief Reads a float value from a python obj
    \param obj the python object
    \param defaultValue a int in case the variable can't be found in the script environment
    \return read out float value
 */
float readFloat(PyObject* obj,float defValue=0.0f);


/*! \fn bool GetIntValue(const std::string& varName,int defaultValue=0)
	\brief Reads a int variable
    \param varName a string with the variable name
    \param defaultValue a int in case the variable can't be found in the script environment
    \return read out int value
 */
int GetIntValue(const std::string& varName,int defaultValue=0);

/*! \fn float GetFloatValue(const std::string& varName,float defaultValue=0.0f)
	\brief Reads a int variable
    \param varName a string with the variable name
    \param defaultValue a float in case the variable can't be found in the script environment
    \return read out float value
 */
float GetFloatValue(const std::string& varName,float defaultValue=0.0f);

/*! \fn GetStrValue(const std::string& varName,const std::string& defaultValue="")
	\brief Reads a string variable
    \param varName a string with the variable name
    \param defaultValue a string in case the variable can't be found in the script environment
    \return read out string value
 */
std::string GetStrValue(const std::string& varName,const std::string& defaultValue="");


/*! \fn int GetIntArray(const std::string& varName,IntList& intList,bool clearArray=true)
	\brief Reads a int array, python lists/tuples -> arrays can hold mixed dataTypes, 
	this function converts all to one dataType
    \param varName a string with the variable name
    \param list a int vector with the variable array
    \param clearArray a flag, if true then the list parameter will be cleared first cleared and then writen
    \return array size
 */
int GetIntArray(const std::string& varName,IntList& list,bool clearArray=true);


/*! \fn int GetFloatArray(const std::string& varName,FloatList& list,bool clearArray=true)
	\brief Reads a int array, python lists/tuples -> arrays can hold mixed dataTypes, 
	this function converts all to one dataType
    \param varName a string with the variable name
    \param list a float vector with the variable array
    \param clearArray a flag, if true then the list parameter will be cleared first cleared and then writen
    \return array size
 */
int GetFloatArray(const std::string& varName,FloatList& list,bool clearArray=true);


/*! \fn int GetStrArray(const std::string& varName,StrList& list,bool clearArray=true)
	\brief Reads a int array, python lists/tuples -> arrays can hold mixed dataTypes, 
	this function converts all to one dataType
    \param varName a string with the variable name
    \param list a str vector with the variable array
    \param clearArray a flag, if true then the list parameter will be cleared first cleared and then writen
    \return array size
 */
int GetStrArray(const std::string& varName,StringList& list,bool clearArray=true);


/*! \fn std::string GetStrDict(const std::string& varName,const std::string& key,const std::string& default="")
	\brief reads a python dictionary as a string value 
    \param varName a string with the variable name
    \param key the key for the dictionary
    \param default default value in case
    \return string result
 */
std::string GetStrDict(const std::string& varName, const std::string& key, const std::string& defaultValue="");


};	// scriptEngine

#endif // SCRIPTENGINE_HXX

