Skip to content
0
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
Collapse
SAMSON Forum
  1. Home
  2. Develop
  3. Simulation
  4. Help with introspection

Help with introspection

Scheduled Pinned Locked Moved Simulation
8 Posts 2 Posters 7.3k Views
  • 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
    K
    Khoa
    wrote on last edited by
    #1

    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
    0
    • K Khoa

      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
      K
      Khoa
      wrote on last edited by Khoa
      #2

      @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
      0
      • K 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
        K
        Khoa
        wrote on last edited by
        #3

        @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

        StephaneS 1 Reply Last reply
        0
        • K Khoa

          @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

          StephaneS
          StephaneS
          Stephane
          wrote on last edited by
          #4

          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
          0
          • StephaneS Stephane

            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
            K
            Khoa
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • StephaneS
              StephaneS
              Stephane
              wrote on last edited by
              #6

              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
              0
              • StephaneS Stephane

                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
                K
                Khoa
                wrote on last edited by
                #7

                @stephane-redon It works ! Thanks.

                1 Reply Last reply
                0
                • StephaneS
                  StephaneS
                  Stephane
                  wrote on last edited by
                  #8

                  ok great!

                  1 Reply Last reply
                  0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Login or register to search.
                  • First post
                    Last post