SAMSON Forum
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • SAMSON Connect
    • Get SAMSON

    Help with introspection

    Simulation
    2
    8
    4960
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Khoa last edited by

      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

      K 1 Reply Last reply Reply Quote 0
      • K
        Khoa @Khoa last edited by 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 ?
        K 1 Reply Last reply Reply Quote 0
        • K
          Khoa @Khoa last edited by

          @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

          Stephane 1 Reply Last reply Reply Quote 0
          • Stephane
            Stephane @Khoa last edited by

            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);
            
            K 1 Reply Last reply Reply Quote 0
            • K
              Khoa @Stephane last edited by

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

              1 Reply Last reply Reply Quote 0
              • Stephane
                Stephane last edited by

                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

                K 1 Reply Last reply Reply Quote 0
                • K
                  Khoa @Stephane last edited by

                  @stephane-redon It works ! Thanks.

                  1 Reply Last reply Reply Quote 0
                  • Stephane
                    Stephane last edited by

                    ok great!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post