Ejemplo n.º 1
0
Rice::Data_Type_Base::Casters &
Rice::Data_Type_Base::
casters()
{
  // Initialize the casters_ if it is null
  if (!casters_)
  {
    // First, see if it has been previously registered with the
    // interpreter (possibly by another extension)
    Class object(rb_cObject);
    Object casters_object(object.attr_get("__rice_casters__"));

    if (casters_object.is_nil())
    {
      // If it is unset, then set it for the first time
      Data_Object<Casters> casters(
          new Casters,
          rb_cObject);
      object.iv_set("__rice_casters__", casters);
      casters_ = casters.get();
    }
    else
    {
      // If it is set, then use the existing value
      Data_Object<Casters> casters(
          casters_object);
      casters_ = casters.get();
    }
  }

  return *casters_;
}
Ejemplo n.º 2
0
inline void Serialiser::decode( std::string const &key, T * &value )
{
    Map::iterator pos = objectContext_->find( key );

    if( pos == objectContext_->end() )
	throw UnknownKeyException( key );

    Primitive &v = pos->second.get();
    Pointer &p = boost::get<Pointer>(v.value);
    int index = p.index;
    if( index == 0 )
	value = 0;
    else
    {
	ObjectCasterMap::iterator ociter = casters().find(p.type);
	if( ociter == casters().end() )
	    throw UnknownTypeException(p.type);

	BaseCasterMap::iterator bciter = ociter->second.find(
	    toast::type_id<T>().name() );
	if( bciter == ociter->second.end() )
	    throw UnknownCastException(p.type, toast::type_id<T>().name());

	IndexObjectMap::iterator diter = decodedPointers_.find(index);

	if( diter != decodedPointers_.end() )
	{
	    value = static_cast<T *>( bciter->second(diter->second) );
	}
	else
	{
	    ClassFactoryMap::iterator fiter = factories().find( p.type );
	    if( fiter == factories().end() )
		throw UnknownTypeException(p.type);

	    ObjectMap::iterator objIter = referencedValues_.find(index);
	    if( objIter == referencedValues_.end() )
		throw ObjectNotDecodedException(p.index);

	    Array *temp = arrayContext_;
	    Array context;
	    context.push_back( objIter->second );
	    void *obj = fiter->second();
	    arrayContext_ = &context;
	    value = static_cast<T *>( bciter->second(obj) );
	    decode( 0, *value );
	    arrayContext_ = temp;
	    decodedPointers_[index] = obj;
	}
    }
}
Ejemplo n.º 3
0
void Serialiser::registerCast( std::string const &derivedID,
    std::string const &baseID, void *(*caster)(void *) )
{
    casters()[derivedID][baseID] = caster;
}