text
stringlengths
0
2.2M
ThreadLocal Reflector::_ciMap;
ClassInfo Reflector::nullclass;
void* TemplateUtil::ddlib = NULL;
Reflector::Reflector()
{
dlib = NULL;
}
Reflector::Reflector(void* dlib)
{
if(dlib == NULL)
{
throw std::runtime_error("Cannot load reflection shared library");
}
this->dlib = dlib;
}
Reflector::~Reflector()
{
/*if(_ciMap.size()>0) {
auto lt = _ciMap.lock_table();
libcuckoo::cuckoohash_map<std::string, ClassInfo*>::locked_table::iterator it;
for(it=lt.begin();it!=lt.end();++it) {
delete it->second;
}
}*/
}
void Reflector::cleanUp()
{
std::map<std::string, ClassInfo*>* ciMap = (std::map<std::string, ClassInfo*>*)_ciMap.get();
if(ciMap!=NULL) {
std::map<std::string, ClassInfo*>::iterator it;
for(it=ciMap->begin();it!=ciMap->end();++it) {
delete it->second;
}
delete ciMap;
}
}
ClassInfo* Reflector::getClassInfo(const std::string& cs, const std::string& app)
{
std::string appName = CommonUtils::getAppName(app);
std::string ca = appName +"_"+ cs;
if(cs.find("::")!=std::string::npos) {
StringUtil::replaceAll(ca, "::", "_");
}
if(_ciMap.get()==NULL) {
_ciMap.set(new std::map<std::string, ClassInfo*>);
}
std::map<std::string, ClassInfo*>* ciMap = (std::map<std::string, ClassInfo*>*)_ciMap.get();
std::map<std::string, ClassInfo*>::iterator it = ciMap->find(ca);
if(it!=ciMap->end()) {
return it->second;
}
void *mkr = dlsym(dlib, ca.c_str());
typedef ClassInfo (*RfPtr) ();
RfPtr f = (RfPtr)mkr;
if(f!=NULL)
{
ClassInfo* t = new ClassInfo();
*t = f();
if(t->getBases().size()>0) {
for(int y=0;y<(int)t->getBases().size();y++) {
if(std::get<0>(t->getBases().at(y))==3) {
ClassInfo* t1 = getClassInfo(std::get<1>(t->getBases().at(y)), app);
if(t1!=NULL) {
if(ciMap->find(std::get<1>(t->getBases().at(y)))==ciMap->end()) {
ciMap->insert({std::get<1>(t->getBases().at(y)), t});
}
t->addRuntimeBase(std::get<1>(t->getBases().at(y)), t1);
}
}
}
}
ciMap->insert({ca, t});
return t;
}
else
return &nullclass;
}
ClassInfo* Reflector::getClassInfo(const std::string& cs, std::string_view app)
{
std::string appName = CommonUtils::getAppName(app);
std::string ca = appName +"_"+ cs;
if(cs.find("::")!=std::string::npos) {
StringUtil::replaceAll(ca, "::", "_");
}
if(_ciMap.get()==NULL) {
_ciMap.set(new std::map<std::string, ClassInfo*>);
}
std::map<std::string, ClassInfo*>* ciMap = (std::map<std::string, ClassInfo*>*)_ciMap.get();
std::map<std::string, ClassInfo*>::iterator it = ciMap->find(ca);
if(it!=ciMap->end()) {
return it->second;
}
void *mkr = dlsym(dlib, ca.c_str());
typedef ClassInfo (*RfPtr) ();
RfPtr f = (RfPtr)mkr;