From Marco Jez, improvements to osgIntrospection, and new automatically generated
osgWrappers/osg set.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <osgIntrospection/Exceptions>
|
||||
#include <osgIntrospection/ReaderWriter>
|
||||
#include <osgIntrospection/Comparator>
|
||||
#include <osgIntrospection/Converter>
|
||||
#include <osgIntrospection/Reflection>
|
||||
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
@@ -27,6 +29,14 @@ Value Value::tryConvertTo(const Type &outtype) const
|
||||
if (type_->isConstPointer() && outtype.isNonConstPointer())
|
||||
return Value();
|
||||
|
||||
// search custom converters
|
||||
ConverterList conv;
|
||||
if (Reflection::getConversionPath(*type_, outtype, conv))
|
||||
{
|
||||
std::auto_ptr<CompositeConverter> cvt(new CompositeConverter(conv));
|
||||
return cvt->convert(*this);
|
||||
}
|
||||
|
||||
std::auto_ptr<ReaderWriter::Options> wopt;
|
||||
|
||||
if (type_->isEnum() && (outtype.getQualifiedName() == "int" || outtype.getQualifiedName() == "unsigned int"))
|
||||
@@ -41,12 +51,11 @@ Value Value::tryConvertTo(const Type &outtype) const
|
||||
const ReaderWriter *dst_rw = outtype.getReaderWriter();
|
||||
if (dst_rw)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
if (src_rw->writeTextValue(oss, *this, wopt.get()))
|
||||
std::stringstream ss;
|
||||
if (src_rw->writeTextValue(ss, *this, wopt.get()))
|
||||
{
|
||||
Value v;
|
||||
std::istringstream iss(oss.str());
|
||||
if (dst_rw->readTextValue(iss, v))
|
||||
if (dst_rw->readTextValue(ss, v))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
@@ -80,107 +89,107 @@ void Value::check_empty() const
|
||||
|
||||
void Value::swap(Value &v)
|
||||
{
|
||||
std::swap(inbox_, v.inbox_);
|
||||
std::swap(type_, v.type_);
|
||||
std::swap(ptype_, v.ptype_);
|
||||
std::swap(inbox_, v.inbox_);
|
||||
std::swap(type_, v.type_);
|
||||
std::swap(ptype_, v.ptype_);
|
||||
}
|
||||
|
||||
bool Value::operator ==(const Value &other) const
|
||||
{
|
||||
if (isEmpty() && other.isEmpty())
|
||||
return true;
|
||||
if (isEmpty() && other.isEmpty())
|
||||
return true;
|
||||
|
||||
if (isEmpty() ^ other.isEmpty())
|
||||
return false;
|
||||
if (isEmpty() ^ other.isEmpty())
|
||||
return false;
|
||||
|
||||
const Comparator *cmp1 = type_->getComparator();
|
||||
const Comparator *cmp2 = other.type_->getComparator();
|
||||
|
||||
const Comparator *cmp = cmp1? cmp1: cmp2;
|
||||
|
||||
if (!cmp)
|
||||
throw ComparisonNotPermittedException(type_->getStdTypeInfo());
|
||||
const Comparator *cmp1 = type_->getComparator();
|
||||
const Comparator *cmp2 = other.type_->getComparator();
|
||||
|
||||
const Comparator *cmp = cmp1? cmp1: cmp2;
|
||||
|
||||
if (!cmp)
|
||||
throw ComparisonNotPermittedException(type_->getStdTypeInfo());
|
||||
|
||||
if (cmp1 == cmp2)
|
||||
return cmp->isEqualTo(*this, other);
|
||||
if (cmp1 == cmp2)
|
||||
return cmp->isEqualTo(*this, other);
|
||||
|
||||
if (cmp1)
|
||||
return cmp1->isEqualTo(*this, other.convertTo(*type_));
|
||||
if (cmp1)
|
||||
return cmp1->isEqualTo(*this, other.convertTo(*type_));
|
||||
|
||||
return cmp2->isEqualTo(convertTo(*other.type_), other);
|
||||
return cmp2->isEqualTo(convertTo(*other.type_), other);
|
||||
}
|
||||
|
||||
bool Value::operator <=(const Value &other) const
|
||||
{
|
||||
const Comparator *cmp1 = type_->getComparator();
|
||||
const Comparator *cmp2 = other.type_->getComparator();
|
||||
|
||||
const Comparator *cmp = cmp1? cmp1: cmp2;
|
||||
|
||||
if (!cmp)
|
||||
throw ComparisonNotPermittedException(type_->getStdTypeInfo());
|
||||
const Comparator *cmp1 = type_->getComparator();
|
||||
const Comparator *cmp2 = other.type_->getComparator();
|
||||
|
||||
const Comparator *cmp = cmp1? cmp1: cmp2;
|
||||
|
||||
if (!cmp)
|
||||
throw ComparisonNotPermittedException(type_->getStdTypeInfo());
|
||||
|
||||
if (cmp1 == cmp2)
|
||||
return cmp->isLessThanOrEqualTo(*this, other);
|
||||
if (cmp1 == cmp2)
|
||||
return cmp->isLessThanOrEqualTo(*this, other);
|
||||
|
||||
if (cmp1)
|
||||
return cmp1->isLessThanOrEqualTo(*this, other.convertTo(*type_));
|
||||
if (cmp1)
|
||||
return cmp1->isLessThanOrEqualTo(*this, other.convertTo(*type_));
|
||||
|
||||
return cmp2->isLessThanOrEqualTo(convertTo(*other.type_), other);
|
||||
return cmp2->isLessThanOrEqualTo(convertTo(*other.type_), other);
|
||||
}
|
||||
|
||||
bool Value::operator !=(const Value &other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
bool Value::operator >(const Value &other) const
|
||||
{
|
||||
return !operator<=(other);
|
||||
return !operator<=(other);
|
||||
}
|
||||
|
||||
bool Value::operator <(const Value &other) const
|
||||
{
|
||||
const Comparator *cmp1 = type_->getComparator();
|
||||
const Comparator *cmp2 = other.type_->getComparator();
|
||||
|
||||
const Comparator *cmp = cmp1? cmp1: cmp2;
|
||||
|
||||
if (!cmp)
|
||||
throw ComparisonNotPermittedException(type_->getStdTypeInfo());
|
||||
const Comparator *cmp1 = type_->getComparator();
|
||||
const Comparator *cmp2 = other.type_->getComparator();
|
||||
|
||||
const Comparator *cmp = cmp1? cmp1: cmp2;
|
||||
|
||||
if (!cmp)
|
||||
throw ComparisonNotPermittedException(type_->getStdTypeInfo());
|
||||
|
||||
if (cmp1 == cmp2)
|
||||
return cmp->isLessThanOrEqualTo(*this, other) && !cmp->isEqualTo(*this, other);
|
||||
if (cmp1 == cmp2)
|
||||
return cmp->isLessThanOrEqualTo(*this, other) && !cmp->isEqualTo(*this, other);
|
||||
|
||||
if (cmp1)
|
||||
{
|
||||
Value temp(other.convertTo(*type_));
|
||||
return cmp1->isLessThanOrEqualTo(*this, temp) && !cmp1->isEqualTo(*this, temp);
|
||||
}
|
||||
if (cmp1)
|
||||
{
|
||||
Value temp(other.convertTo(*type_));
|
||||
return cmp1->isLessThanOrEqualTo(*this, temp) && !cmp1->isEqualTo(*this, temp);
|
||||
}
|
||||
|
||||
Value temp(convertTo(*other.type_));
|
||||
return cmp2->isLessThanOrEqualTo(temp, other) && !cmp2->isEqualTo(temp, other);
|
||||
Value temp(convertTo(*other.type_));
|
||||
return cmp2->isLessThanOrEqualTo(temp, other) && !cmp2->isEqualTo(temp, other);
|
||||
}
|
||||
|
||||
bool Value::operator >=(const Value &other) const
|
||||
{
|
||||
const Comparator *cmp1 = type_->getComparator();
|
||||
const Comparator *cmp2 = other.type_->getComparator();
|
||||
|
||||
const Comparator *cmp = cmp1? cmp1: cmp2;
|
||||
|
||||
if (!cmp)
|
||||
throw ComparisonNotPermittedException(type_->getStdTypeInfo());
|
||||
const Comparator *cmp1 = type_->getComparator();
|
||||
const Comparator *cmp2 = other.type_->getComparator();
|
||||
|
||||
const Comparator *cmp = cmp1? cmp1: cmp2;
|
||||
|
||||
if (!cmp)
|
||||
throw ComparisonNotPermittedException(type_->getStdTypeInfo());
|
||||
|
||||
if (cmp1 == cmp2)
|
||||
return !cmp->isLessThanOrEqualTo(*this, other) || cmp->isEqualTo(*this, other);
|
||||
if (cmp1 == cmp2)
|
||||
return !cmp->isLessThanOrEqualTo(*this, other) || cmp->isEqualTo(*this, other);
|
||||
|
||||
if (cmp1)
|
||||
{
|
||||
Value temp(other.convertTo(*type_));
|
||||
return !cmp1->isLessThanOrEqualTo(*this, temp) || cmp1->isEqualTo(*this, temp);
|
||||
}
|
||||
if (cmp1)
|
||||
{
|
||||
Value temp(other.convertTo(*type_));
|
||||
return !cmp1->isLessThanOrEqualTo(*this, temp) || cmp1->isEqualTo(*this, temp);
|
||||
}
|
||||
|
||||
Value temp(convertTo(*other.type_));
|
||||
return !cmp2->isLessThanOrEqualTo(temp, other) || cmp2->isEqualTo(temp, other);
|
||||
Value temp(convertTo(*other.type_));
|
||||
return !cmp2->isLessThanOrEqualTo(temp, other) || cmp2->isEqualTo(temp, other);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user