From Marco Jez, improvements to osgIntrospection, and new automatically generated

osgWrappers/osg set.
This commit is contained in:
Robert Osfield
2005-04-07 20:00:17 +00:00
parent 5b4482c70d
commit 7a27a0bef7
132 changed files with 8608 additions and 301 deletions

View File

@@ -1,6 +1,7 @@
#include <osgIntrospection/Reflection>
#include <osgIntrospection/Exceptions>
#include <osgIntrospection/Type>
#include <osgIntrospection/Converter>
#include <OpenThreads/Mutex>
#include <OpenThreads/ScopedLock>
@@ -11,6 +12,20 @@ using namespace osgIntrospection;
Reflection::StaticData *Reflection::staticdata__ = 0;
Reflection::StaticData::~StaticData()
{
for (TypeMap::iterator i=typemap.begin(); i!=typemap.end(); ++i)
delete i->second;
for (ConverterMapMap::iterator i=convmap.begin(); i!=convmap.end(); ++i)
{
for (ConverterMap::iterator j=i->second.begin(); j!=i->second.end(); ++j)
{
delete j->second;
}
}
}
const TypeMap &Reflection::getTypes()
{
return getOrCreateStaticData().typemap;
@@ -48,13 +63,13 @@ const Type &Reflection::getType(const std::string &qname)
const TypeMap &types = getTypes();
for (TypeMap::const_iterator i=types.begin(); i!=types.end(); ++i)
{
{
if (i->second->isDefined() && i->second->getQualifiedName().compare(qname) == 0)
return *i->second;
for (int j=0; j<i->second->getNumAliases(); ++j)
if (i->second->getAlias(j).compare(qname) == 0)
return *i->second;
}
for (int j=0; j<i->second->getNumAliases(); ++j)
if (i->second->getAlias(j).compare(qname) == 0)
return *i->second;
}
throw TypeNotFoundException(qname);
}
@@ -77,22 +92,74 @@ Type *Reflection::getOrRegisterType(const std::type_info &ti, bool replace_if_de
TypeMap::iterator i = tm.find(&ti);
if (i != tm.end())
{
if (replace_if_defined && i->second->isDefined())
{
std::string old_name = i->second->getName();
std::string old_namespace = i->second->getNamespace();
std::vector<std::string> old_aliases = i->second->aliases_;
{
if (replace_if_defined && i->second->isDefined())
{
std::string old_name = i->second->getName();
std::string old_namespace = i->second->getNamespace();
std::vector<std::string> old_aliases = i->second->aliases_;
Type *newtype = new (i->second) Type(ti);
newtype->name_ = old_name;
newtype->namespace_ = old_namespace;
newtype->aliases_.swap(old_aliases);
Type *newtype = new (i->second) Type(ti);
newtype->name_ = old_name;
newtype->namespace_ = old_namespace;
newtype->aliases_.swap(old_aliases);
return newtype;
}
return i->second;
}
return newtype;
}
return i->second;
}
return registerType(ti);
}
void Reflection::registerConverter(const Type &source, const Type &dest, const Converter *cvt)
{
getOrCreateStaticData().convmap[&source][&dest] = cvt;
}
const Converter *Reflection::getConverter(const Type &source, const Type &dest)
{
return getOrCreateStaticData().convmap[&source][&dest];
}
bool Reflection::getConversionPath(const Type &source, const Type &dest, ConverterList &conv)
{
ConverterList temp;
std::vector<const Type *> chain;
if (accum_conv_path(source, dest, temp, chain))
{
conv.swap(temp);
return true;
}
return false;
}
bool Reflection::accum_conv_path(const Type &source, const Type &dest, ConverterList &conv, std::vector<const Type *> &chain)
{
// break unwanted loops
if (std::find(chain.begin(), chain.end(), &source) != chain.end())
return false;
// store the type being processed to avoid loops
chain.push_back(&source);
StaticData::ConverterMapMap::const_iterator i = getOrCreateStaticData().convmap.find(&source);
if (i == getOrCreateStaticData().convmap.end())
return false;
const StaticData::ConverterMap &cmap = i->second;
StaticData::ConverterMap::const_iterator j = cmap.find(&dest);
if (j != cmap.end())
{
conv.push_back(j->second);
return true;
}
for (j=cmap.begin(); j!=cmap.end(); ++j)
{
if (accum_conv_path(*j->first, dest, conv, chain))
return true;
}
return false;
}