Abstract plugin



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 10/03/2011 at 06:13, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   12 
    Platform:   Windows  ; Mac  ;  
    Language(s) :     C++  ;

    ---------
    I need to create an abstract plugin derived from ObjectData.
    I am not sure how to declare the abstract plugin from which to derive all others plugins (think something like EffectorData).
    I am not clear if the basic plugin should be registered (have its own ID). It Will only have virtual methods, and in any case shall be used directly.
    Then I did several tests but in no way I can derive a plugin from my base type. Someone can give me an example of such a thing:

      
      
    //Base plugin in BasePlugin.h file   
      
    class MyBasePlugin : public ObjectData   
    {   
         public:   
    virtual Bool Init(GeListNode *node);   
    .   
    .   
    //new abstract methods   
    virtual Bool makethis(void);   
    virtual Bool makethat(void);   
      
    }   
      
    //Derived plugin in DerivedPlugin.cpp file   
      
    class MyDerivedPlugin : public MyBasePlugin   
    {   
         public:   
    virtual Bool Init(GeListNode *node);   
    .   
    .   
    //new abstract methods   
    virtual Bool makethis(void);   
    virtual Bool makethat(void);   
      
    }   
      
    

    thank's
    Lorenzo



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/03/2011 at 04:28, xxxxxxxx wrote:

    "Then I did several tests but in no way I can derive a plugin from my base type."

    -In what way did this fail? The example you give certainly looks like it should be able to work.

    BTW, why do you need this?

    Best regards
    /Filip



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/03/2011 at 05:46, xxxxxxxx wrote:

    When compile I have some errors, the compiler can't find the virtual methods in the BasePlugin.

    For example: External symbol BasePlugin::Init(..) unresolved ???

    but the   "BasePlugin.h" inclusion is present!

    Maybe is a c++ problem (I'm not a c++ wizard, usually I work with other languages), but I'm not able to make it work!?

    The idea was about the possibility to create a group of effects plugins derived from the same abstract plugin type, this allows me to work so much easier.

    thanks
    Lorenzo



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/03/2011 at 09:26, xxxxxxxx wrote:

    I haven't tried to do anything like this myself, but I don't think you should declare Init() in your class MyBasePlugin unless you are going to provide an implementation. In other words, Init() is declared (as virtual) in the NodeData class from which ObjectData is derived. If you declare it again, the compiler expects to find an implementation, but you want that to occur in your MyDerivedPlugin class. The same would be true of other virtual functions declared in the parent class.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/03/2011 at 03:06, xxxxxxxx wrote:

    Thank's splender the problem was just that!
    It seems that in C ++ should always implement the methods declared in the header even if the class is never instantiated!
    Working in Delphi things are a bit different. You may define abstract methods that do not need an implementation and then inheritance is a little different.
    This caused me some confusion.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/03/2011 at 04:35, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    It seems that in C ++ should always implement the methods declared in the header even if the class is never instantiated!

    You can avoid this in C++ if your class is "pure virtual", see e.g. this article:

    http://www.exforsys.com/tutorials/c-plus-plus/c-pure-virtual-function-and-base-class.html

    /Filip



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/03/2011 at 06:22, xxxxxxxx wrote:

    Thank's FilipM this will take the same effects that I have with "Abstract" directive in Delphi!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/03/2011 at 16:11, xxxxxxxx wrote:

    Howdy,

    Looking at your code I think your virtual functions:

    virtual Bool makethis(void);
      
    virtual Bool makethat(void);
    

    will never get called.

    Your base class needs to call them.

    Here is an example I tested with a base class derived from a TagData class that actually worked:

    class CDTagData : public TagData
    {
    public:
    	virtual Bool DoDraw(BaseTag *tag, BaseObject *op, BaseDraw *bd, BaseDrawHelp *bh)=0;
    	virtual Bool DoExecute(BaseTag *tag, BaseDocument *doc, BaseObject *op, BaseThread *bt, LONG priority, LONG flags)=0;
    	
    	virtual Bool Draw(PluginTag *tag, BaseObject *op, BaseDraw *bd, BaseDrawHelp *bh)
    	{
    		return DoDraw(tag,op,bd,bh);
    	}
    	virtual LONG Execute(PluginTag *tag, BaseDocument *doc, BaseObject *op, BaseThread *bt, LONG priority, LONG flags)
    	{
    		if(!DoExecute(tag,doc,op,bt,priority,flags)) return EXECUTION_RESULT_USERBREAK;
    		else return EXECUTION_RESULT_OK;
    	}
    };
      
    class CDTagTestPlugin : public CDTagData
    {
    	public:
    		virtual Bool Init(GeListNode *node);
    		virtual Bool Message(GeListNode *node, LONG type, void *data);
    		
    		virtual Bool DoDraw(BaseTag *tag, BaseObject *op, BaseDraw *bd, BaseDrawHelp *bh);
    		virtual Bool DoExecute(BaseTag *tag, BaseDocument *doc, BaseObject *op, BaseThread *bt, LONG priority, LONG flags);
      
    		static NodeData *Alloc(void) { return gNew CDTagTestPlugin; }
    };
    

    As you can see in the above code the base class of "CDTagData" only includes the calling methods to call the new abstract virtual functions "DoDraw" and "DoExecute". In the derived class of "CDTagTestPlugin" the functions "Init" and "Message" were inherited directly from the NodeData class and not the CDTagData base class.

    So, in your "MyBasePlugin" class you need to use one of the ObjectData class's virtual functions to call your "makethis" and "makethat" functions. Otherwise they will never get called. And also, your base class shouldn't have the Init function.

    Adios,
    Cactus Dan



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/03/2011 at 03:18, xxxxxxxx wrote:

    Thank's Dan,
    I read your response carefully and I think I understand what you mean.
    It's true what you say but my intention was another!
    The virtual functions (makethis and makethat) would then be called from other plugin.
    The problem is that I don't know if it is possible. I did some tests and seems to work fine, but I don't know if this is a safe method!
    An example to better understand:

    Considers a type generator plugin, we call it GEN!
    Consider a second one (Objectplugin type), we call it EFFECTOR!
    GEN include the header of EFFECTOR and know the EFFECTOR class.
    EFFECTOR has a new PUBLIC function called MAKETHIS.
    Many plugins of EFFECTOR type can be placed on a list IN_Exclude present in the GEN description.
    In the Doexecute function of GEN I read the EFFECTOR plugin present in the list then I call then MAKETHIS function of each plugin.
    I made some test and this seems work fine!
    Because I had different types of EFFECTOR plugin, I wanted to make a base type from which to derive all others, to call the same method MAKETHIS but belonged to a different type of plugin.
    In my tests I failed however to make it(to long now to explain why), so I decided to combine all types of EFFECTOR in a single plugin in which can be activated only the ones you want!

    Can someone tell me if this method can be considered safe && valid?

    thank's
    Lorenzo



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/03/2011 at 06:53, xxxxxxxx wrote:

    Howdy,

    The subject of using virtual functions across .dylib/.cdl libraries was discussed before in this thread:
    https://plugincafe.maxon.net/topic/5348/5350_safe-use-of-virtual&KW=virtual+function

    ... but the question of whether or not it was safe to do so was never answered.

    I chose not to use the virtual method, described in that thread, because it would be incompatible with older versions of the accessed plugin, and because I never could find an answer on whether or not it was safe. Googling "c++ virtual function" only gives results about using it with class inheritance.

    Adios,
    Cactus Dan


Log in to reply