My environment is Visual Studio 2008.
I have 3 different libraries. In a summarized manner the behaviors of them are equivalent as follows.
Library 1 - Offers functions to be registered
class FunctionRegistry
{
typedef std::list<int> TListInt;
TListInt m_Params;
void * m_FPtr;
public:
FunctionRegistry(void * fptr):m_FPtr(fptr){}
FunctionRegistry& Insert(int value){m_Params.push_back(value); return *this;}
void Call();
};
void FunctionRegistry::Call()
{
/*this is the area I want to get rid of */
TListInt::iterator ite = m_Params.begin();
while (ite != m_Params.end());
{
__asm push *ite;//I want to remvoe this assmebly code somehow
++ite;//Edited after initial post
}
((void(*)())m_FPtr)();
ite = m_Params.begin();
while (ite != m_Params.end());
{
int i = 0;
__asm pop i;//I want to remvoe this assmebly code somehow
++ite;//Edited after initial post
}
/*end of area to get rid of*/
}
Library 2 - Defines a set of functions like
void foo(int i, int j)
{
std::cout << "foo int int " << i << " " << j << std::endl;
}
void bar(int i)
{
std::cout << "bar int " << i << std::endl;
}
void biz()
{
std::cout << "biz" << std::endl;
}
FunctionRegistry fRegFoo((void*)&foo);
fRegFoo.Insert(10).Insert(20);
FunctionRegistry fRegBar((void*)&bar);
fRegBar.Insert(10);
FunctionRegistry fRegBiz((void*)&biz);
Library 3 - This is the user of above two libraries and a sample usage would be like,
fRegFoo.Call();
fRegBar.Call();
fRegBiz.Call();
This is a legacy code and I'm trying now to get rid of above assembly code. I can easily change (with some API changes) my library 1 to cope with my need. But my problem is, due to massive distribution of the libraries among a large number of users, asking them to change their use cases (here library 3) according API changes of library 1 should be my last option.
Now, I am seeking your help, is there any way to change my library 1 internals with whatever possible techniques without changing its API to eliminate this assembly code?
If you think, it can't be achieved without any API change, please suggest ways having minimal code changes to library 3.