Help with introspection



  • I have a class with the function 'reset' exposed as such

    SB_CLASS_BEGIN(SEStateUpdaterFIRE);
    
    	SB_CLASS_TYPE(SBCClass::StateUpdaterParticleSystem);
            SB_CLASS_DESCRIPTION("FIRE");
    
    	SB_FACTORY_BEGIN;
    
    		SB_CONSTRUCTOR_2(SEStateUpdaterFIRE, SBParticleSystem*, SBMInteractionModelParticleSystem*);
    
    	SB_FACTORY_END;
    
    	SB_INTERFACE_BEGIN;
    
            SB_FUNCTION_0(void, SEStateUpdaterFIRE, reset);
    
    	SB_INTERFACE_END;
    
    SB_CLASS_END(SEStateUpdaterFIRE);
    

    In my app, I call the function 'reset' from stateUpdaterParticleSystem which is of SBPointer<SBSStateUpdaterParticleSystem> type as follows:

    	if (stateUpdaterParticleSystem->getProxy()->getName() == "SEStateUpdaterFIRE") {
    		stateUpdaterParticleSystem->getProxy()->call(stateUpdaterParticleSystem(), "reset");
    	}
    

    However, I get compile error "use of undefined type 'SBCClassObjectHolder<U>'" from SBCMetaValue.hpp at line 267.

    Does anyone know how to get around this problem in SAMSON 0.7.0 ?

    Khoa



  • @khoa

    It seems it can perform upcasting but not downcasting (see SBCMetaCast.hpp)

    static SBCMetaValueBase* castFrom(SBCMetaValueBase* fromValue) {
    
    		if (!fromValue) return 0;
    
    		std::string classTypeName = fromValue->getClassTypeName();
    		std::string fromTypeName = fromValue->getTypeName();
    		std::string toTypeName = SBCMetaType<ToType*>::getTypeName();
    
    		if (fromTypeName.compare(toTypeName) == 0) return new SBCMetaValueHolder<ToType*>((static_cast<SBCMetaValueHolder<ToType*>*>(fromValue))->getValue());
    		else if (fromValue->isPointerType()) {
    
    			// determine whether the type in fromValue inherits from ToType
    
    			SBCMetaValueBase* currentType = fromValue->getParentType();
    			std::string toTypeParentName = SBCMetaType<ToType>::getTypeName();
    
    			while (currentType->hasBaseType()) {
    
    				currentType = currentType->getBaseType();
    
    				if (currentType->getTypeName().compare(toTypeParentName) == 0) {
    
    					ToType* value = (static_cast<SBCMetaValueHolder<ToType*>*>(fromValue))->getValue();
    					return new SBCMetaValueHolder<ToType*>(value);
    
    				}
    
    			}
    
    		}
    
    		return 0;
    
    	}```
    
    Anyone has a workaround ?


  • @khoa

    I just figured out one work-around, that is add a down-casting in SBCMetaCast.hpp as such

    static SBCMetaValueBase* castFrom(SBCMetaValueBase* fromValue) {
    
    		if (!fromValue) return 0;
    
    		std::string fromTypeName = fromValue->getTypeName();
    		std::string toTypeName = SBCMetaType<ToType*>::getTypeName();
    
    		if (fromTypeName.compare(toTypeName) == 0) return new SBCMetaValueHolder<ToType*>((static_cast<SBCMetaValueHolder<ToType*>*>(fromValue))->getValue());
    		else if (fromValue->isPointerType()) {
    
    			// determine whether the type in fromValue inherits from ToType
    
    			SBCMetaValueBase* currentType = fromValue->getParentType();
    			std::string toTypeParentName = SBCMetaType<ToType>::getTypeName();
    
    			while (currentType->hasBaseType()) {
    
    				currentType = currentType->getBaseType();
    
    				if (currentType->getTypeName().compare(toTypeParentName) == 0) {
    
    					ToType* value = (static_cast<SBCMetaValueHolder<ToType*>*>(fromValue))->getValue();
    					return new SBCMetaValueHolder<ToType*>(value);
    
    				}
    
    			}
    			
    			// down casting (determine whether the type in toType inherits from the type of fromValue)
    			SBCMetaValueType<ToType*> toType;
    			currentType = toType.getParentType();
    
    			while (currentType->hasBaseType()) {
    
    				currentType = currentType->getBaseType();
    				std::string currentTypeName = currentType->getTypeName() + "*";
    
    				if (currentTypeName.compare(fromTypeName) == 0) {
    
    					ToType* value = (static_cast<SBCMetaValueHolder<ToType*>*>(fromValue))->getValue();
    					return new SBCMetaValueHolder<ToType*>(value);
    
    				}
    
    			}
    
    		}
    
    

    It may not be good because I have to modify SBCMetaCast.hpp which is provided by the SDK. But at least it solves my problem for now.
    If anyone has a better solution, please let me know.

    Have a great weekend.

    Khoa



  • Hi Khoa, yes, you should not have to modify this SDK file :-). Instead, you have to let the type system know that your class derives from the updater class. Precisely, in your SEStateUpdaterFIRE.hpp file that contains the description of the SEStateUpdaterFIRE class, you should have a line like this after the class description:

    SB_DECLARE_BASE_TYPE(SEStateUpdaterFIRE, SBSStateUpdaterParticleSystem);
    


  • @stephane-redon Actually I had that line in the first place and it didn't work



  • Sorry for the delay, you need to use the getThis() function to pass the actual pointer type to the call function:

    stateUpdaterParticleSystem->getProxy()->call(stateUpdaterParticleSystem->getThis(), "reset");
    

    Stephane



  • @stephane-redon It works ! Thanks.



  • ok great!


Log in to reply
 















Web
Analytics

Looks like your connection to SAMSON Connect - Forum was lost, please wait while we try to reconnect.