//-------------------------------------------------------------------------------------------------
// <copyright file="LqrSMACLuaEventConversion.h" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
//		Declarations for LuaEventConversion class, which contains methos for
//		converting events and event parameters between lua and the C++/CORBA forms.
// </summary>
//
// <owner>Mike Cookson</owner>
//-------------------------------------------------------------------------------------------------

#ifndef __LqrSMACLuaEventConversion_h__
#define __LqrSMACLuaEventConversion_h__

#include "LqrSMACIObjectBroker.h"
#include "LqrSMACLuaInstance.h"
#include "IEventBase.h"
#include <string>
#include <vector>

namespace LiquidRobotics {
namespace SMACFramework {

class SHARED_LIB_PUBLIC LuaEventConversion
{
public:

	typedef LiquidRobotics::EventLib::IEventBase IEventBase;
	typedef LiquidRobotics::SMACFramework::IObjectBroker IObjectBroker;
	typedef LuaInstance::Number Number;
	typedef std::string string;
	typedef std::vector<bool> BoolArray;
	typedef std::vector<Number> NumberArray;
	typedef std::vector<string> StringArray;
	typedef IEventBase::PropertyValueType PVT;
	typedef PVT::Ptr PVTPtr;

	LuaEventConversion(LuaInstance& _L, IObjectBroker& _broker);

	IEventBase::Ptr GetEvent(int stackOffset = -1);
	PVTPtr GetPropertyValue(int stackOffset = -1);
	void PushEvent(IEventBase& evt, const char* varName = NULL);
	void PushPropertyValue(const PVT& pvt);

private:

	typedef LiquidRobotics::EventLib::EventType EventType;

	template<typename T, typename V>
	bool ConvertArray(const T inref, V& result);

	template<typename T>
	bool ConvertStr(const T inref, string& result);

	template<typename T>
	void PushArray(typename T::VECT& array, const char* varName = NULL);

	void ConvertArrayTable(int stackOffset, PVT& result);
	PVTPtr GetBasicPropertyValue(int stackOffset = -1);
	PVTPtr GetCoercedPropertyValue(int stackOffset, PVT::StorageType targetType);
	//void PushEventType(const EventType& etype, const char* varName = NULL);
	void PushProperties(IEventBase& evt, const char* varName = NULL);
	void PushNumberArray(const NumberArray& numA, const char* varName = NULL);
	void PushStringArray(const StringArray& strA, const char* varName = NULL);
	//void SetNamedEventTypeField(const string& fieldName, const EventType& eventType, int stackOffset = -3);
	void SetNamedStringField(const string& fieldName, string strVal, int stackOffset = -3);
	void SetNamedNumericField(const string& fieldName, double numVal, int stackOffset = -3);
	void SetNamedPropertiesField(const string& fieldName, IEventBase& evt, int stackOffset = -3);
	void SetOptionalName(const char* varName);
#if 0
	void ValidateArrayTable(int stackOffset = -1);
	void ValidateEventType(int stackOffset = -1);
	void ValidateEventStructure(int stackOffset = -1);
	void ValidateProperties(int stackOffset = -1);
#endif

	LuaInstance& L;
	IObjectBroker& broker;
};

}
}

#endif
