PokemonScriptTester/src/Tester/TestEnvironment.hpp

32 lines
791 B
C++
Raw Permalink Normal View History

2021-08-22 17:03:03 +00:00
#ifndef POKEMONSCRIPTTESTER_TESTENVIRONMENT_HPP
#define POKEMONSCRIPTTESTER_TESTENVIRONMENT_HPP
struct TestEnvironment {
size_t TotalRequirements = 0;
size_t FailedRequirements = 0;
template <typename T> void AddGarbage(T* data) { _garbage.Append(GarbageObject(data)); }
void CollectGarbage() {
for (auto& o : _garbage) {
o.Destructor(o.Ptr);
}
_garbage.Clear();
}
private:
struct GarbageObject {
void* Ptr;
std::function<void(void* ptr)> Destructor;
template <typename T> GarbageObject(T* ptr) {
Ptr = ptr;
Destructor = [](void* v) { delete static_cast<T*>(v); };
}
};
ArbUt::List<GarbageObject> _garbage;
2021-08-22 17:03:03 +00:00
};
#endif // POKEMONSCRIPTTESTER_TESTENVIRONMENT_HPP