Fixing Fake.h to use an interface in the list and compile Fake.h to check syntax.
This commit is contained in:
parent
fba5287da2
commit
5e0d6e43fc
1
Call.cpp
1
Call.cpp
|
@ -1,4 +1,5 @@
|
||||||
#include "elfspy/Call.h"
|
#include "elfspy/Call.h"
|
||||||
|
#include "elfspy/Fake.h"
|
||||||
|
|
||||||
namespace spy
|
namespace spy
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,18 +16,12 @@ namespace spy
|
||||||
* The constructor installs the new function in place of the function, the
|
* The constructor installs the new function in place of the function, the
|
||||||
* destructor uninstalls it
|
* destructor uninstalls it
|
||||||
*/
|
*/
|
||||||
class Fake;
|
|
||||||
|
class FakeI {
|
||||||
|
};
|
||||||
|
extern std::vector<std::shared_ptr<FakeI>> fake_list;
|
||||||
template <typename H, typename ReturnType, typename... ArgTypes>
|
template <typename H, typename ReturnType, typename... ArgTypes>
|
||||||
extern std::vector<std::shared_ptr<Fake>> fake_list;
|
class Fake : FakeI
|
||||||
void delete_mocks (void) {
|
|
||||||
while (fake_list.size () != 0) {
|
|
||||||
auto index = fake_list.size() - 1;
|
|
||||||
auto element = fake_list[index];
|
|
||||||
fake_list.erase (&fake_list[index]);
|
|
||||||
delete element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class Fake
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Fake(H& hook, ReturnType (*func)(ArgTypes...));
|
Fake(H& hook, ReturnType (*func)(ArgTypes...));
|
||||||
|
@ -52,18 +46,13 @@ inline Fake<H, ReturnType, ArgTypes...>::~Fake()
|
||||||
hook_.patch(func_);
|
hook_.patch(func_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename H, typename ReturnType, typename... ArgTypes>
|
|
||||||
void fake(H& hook, ReturnType (*patch)(ArgTypes...)) {
|
|
||||||
auto shared_ptr = std::make_shared<Fake<H, ReturnType, ArgTypes...>> (hook, patch);
|
|
||||||
fake_list.push_back (shared_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename H, typename ReturnType, typename... ArgTypes>
|
template <typename H, typename ReturnType, typename... ArgTypes>
|
||||||
inline auto new_fake(H& hook, ReturnType (*patch)(ArgTypes...))
|
inline auto new_fake(H& hook, ReturnType (*patch)(ArgTypes...))
|
||||||
-> Fake<H, ReturnType, ArgTypes...>*
|
-> Fake<H, ReturnType, ArgTypes...>*
|
||||||
{
|
{
|
||||||
return new Fake<H, ReturnType, ArgTypes...>(hook, patch);
|
auto instance = std::make_shared<Fake<H, ReturnType, ArgTypes...>>(hook, patch);
|
||||||
|
fake_list.push_back (instance);
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace elfspy
|
} // namespace elfspy
|
||||||
|
|
Loading…
Reference in New Issue