我的开发环境是Visual Studio 2008。
我有三个不同的库。简单概括它们的行为如下:
库1 - 提供可注册的函数
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 - 定义了一组函数,如下:
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);
图书馆 3 - 这是上述两个库的用户,一个示例用法可能是:
fRegFoo.Call();
fRegBar.Call();
fRegBiz.Call();
这是一段遗留代码,我现在试图摆脱上面的汇编代码。我可以轻松地更改(通过一些API更改)我的库1以满足我的需求。但是我的问题是,由于库已广泛分发给大量用户,要求他们根据库1的API更改其用例(例如库3)应该是我最后的选择。
现在,我需要您的帮助,是否有任何方法可以在不更改API的情况下使用任何可能的技术更改我的库1内部以消除此汇编代码?
如果您认为无法在不更改API的情况下实现,请建议对库3的代码更改最小的方式。