|
#pragma once
#include "RetTypeSpecificator.hpp"
class ActionInterface
{
public:
virtual ~ActionInterface(){}
virtual void DoAction() = 0;
virtual Base_Value_Storage * ReturnValue() = 0;
};
template<typename ret_type, typename Action, typename Handler >
class ActionHolder : public ActionInterface
{
Action m_Action;
Handler * m_Handler;
bool m_bDeleteHandler;
RetValueStorage<ret_type> m_RetValueHolder;
public:
ActionHolder(Action act, Handler * pHandler, bool bDeleteHandler) : m_Action(act),
m_Handler(pHandler), m_bDeleteHandler(bDeleteHandler)
{
cout<<"Inside ActionHolder. RetValueStorage<ret_type> has ID = "<<m_RetValueHolder.m_RetType<<endl;
}
~ActionHolder()
{
if(m_bDeleteHandler)
delete m_Handler;
}
template<typename T>
void CallFunctor()
{
m_RetValueHolder.m_tData = m_Action();
(*m_Handler)(m_RetValueHolder.m_tData);
}
template<>
void CallFunctor<void>()
{
m_Action();
}
virtual void DoAction()
{
CallFunctor<ret_type>();
/*
// unfortunately, runtime logic hasn't authority for templates ...
TypeDeductor<void> voidType;
TypeDeductor<ret_type> retType;
if(voidType == retType)
m_Action();
else
{
m_RetValueHolder.m_tData = m_Action(); // here compiler becomes angry - cannot convert void to anything...
if(m_bThereIsHandler)
(*m_Handler)(m_RetValueHolder.m_tData);
}
*/
}
// this is the only (maybe) decent way to return outside data returned from m_Action call;
// after all we must remember what return type was defined in AddActionToSequence<ret_type> call in main.
virtual Base_Value_Storage * ReturnValue()
{
RetValueStorage<ret_type> * pRet = new RetValueStorage<ret_type>(m_RetValueHolder);
return pRet;
}
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.