ClassNameCheck tracks class names used

Each time the ClassNameCheck constructor is called it adds to the list
of class names given to it, which can later be retrieved by a class
static method.
develop
Matthew Cline 2011-07-24 21:24:34 -07:00
parent caf6f881df
commit 41130cb613
2 changed files with 47 additions and 11 deletions

@ -567,6 +567,42 @@ int Core::SDL_Event(SDL::Event* ev, int orig_return)
// do stuff with the events...
}
////////////////
// ClassNamCheck
////////////////
// Since there is no Process.cpp, put ClassNamCheck stuff in Core.cpp
static std::set<std::string> known_class_names;
static std::map<std::string, void*> known_vptrs;
ClassNameCheck::ClassNameCheck(std::string _name) : name(_name), vptr(0)
{
known_class_names.insert(name);
}
ClassNameCheck &ClassNameCheck::operator= (const ClassNameCheck &b)
{
name = b.name; vptr = b.vptr; return *this;
}
bool ClassNameCheck::operator() (Process *p, void * ptr) const {
if (vptr == 0 && p->readClassName(ptr) == name)
{
vptr = ptr;
known_vptrs[name] = ptr;
}
return (vptr && vptr == ptr);
}
void ClassNameCheck::getKnownClassNames(std::vector<std::string> &names)
{
std::set<std::string>::iterator it = known_class_names.begin();
for (; it != known_class_names.end(); it++)
names.push_back(*it);
}
/*******************************************************************************
M O D U L E S
*******************************************************************************/

@ -282,18 +282,18 @@ namespace DFHack
{
std::string name;
mutable void * vptr;
public:
ClassNameCheck() : vptr(0) {};
ClassNameCheck(std::string _name) : name(_name), vptr(0) {};
ClassNameCheck &operator= (const ClassNameCheck &b)
{
name = b.name; vptr = b.vptr; return *this;
}
bool operator() (Process *p, void * ptr) const {
if (vptr == 0 && p->readClassName(ptr) == name)
vptr = ptr;
return (vptr && vptr == ptr);
};
ClassNameCheck() : vptr(0) {}
ClassNameCheck(std::string _name);
ClassNameCheck &operator= (const ClassNameCheck &b);
// Is the class name of the given virtual table pointer the same as the
// name for thei ClassNameCheck object?
bool operator() (Process *p, void * ptr) const;
// Get list of names given to ClassNameCheck constructors.
static void getKnownClassNames(std::vector<std::string> &names);
};
}
#endif