Exemple #1
0
bool Reflection::accum_conv_path(const Type& source, const Type& dest, ConverterList& conv, std::vector<const Type* > &chain, CastType castType)
{
    // 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);

    // search a converter from "source"
    StaticData::ConverterMapMap::const_iterator i = getOrCreateStaticData().convmap.find(&source);
    if (i == getOrCreateStaticData().convmap.end())
        return false;

    // search a converter to "dest"
    const StaticData::ConverterMap& cmap = i->second;
    StaticData::ConverterMap::const_iterator j = cmap.find(&dest);
    if (j != cmap.end() && (j->second->getCastType() == castType))
    {
        conv.push_back(j->second);
        return true;
    }

    // search a undirect converter from "source" to ... to "dest"
    for (j=cmap.begin(); j!=cmap.end(); ++j)
    {
        if ((j->second->getCastType() == castType) && accum_conv_path(*j->first, dest, conv, chain, castType))
        {
            conv.push_front(j->second);
            return true;
        }
    }

    return false;
}
Exemple #2
0
const AdapterChain::ConverterList AdapterChain::translateConverterids(const AdapterChain::ConverteridList &&ids)
{
    ConverterList   ret;
    ret.reserve(ids.size());
    for (const auto id : ids)
    {
        ret.push_back(&global.converters.get(id));
    }
    return ret;
}
Exemple #3
0
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, STATIC_CAST))
    {
        conv.swap(temp);
        return true;
    }

    if (source.isPointer() && dest.isPointer())
    {
        chain.clear();
        temp.clear();
        if (accum_conv_path(source, dest, temp, chain, DYNAMIC_CAST))
        {
            conv.swap(temp);
            return true;
        }
    }

    return false;
}