Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    MAXON Data Type and explicit constructors

    Cinema 4D SDK
    c++ r20 windows
    2
    7
    1.4k
    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.
    • M
      mp5gosu
      last edited by

      Is it possible to define an explicit constructor for Custom Data Types?
      In the examples provided here, the triplet is configured after allocating it.

      I would like to initialize my type upon creation. Is this possible?

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi mp5gosu, thanks for reaching us.

        I'm a bit confused, since reading the topic and the documentation reference, it's unclear the question about explicit constructor on CustomDataType. MAXON Data Type and CustomDataType - and the related CustomDataTypeClass - address different needs in terms of development.
        Whilst the former is a convenient way to define and register new data structures inside the MAXON AP, used in conjunction with MAXON::DataDictionary, the second is the base class from which Cinema CustomDataType(s) are inherited from, used in conjuction with BaseContainers, and which are used to stored the data from the respective CustomGui(s) (think about the Gradient custom data type and the GradientGui)

        That said, can you please elaborate what do you mean by Is it possible to define an explicit constructor for Custom Data Types?

        Best, Riccardo

        1 Reply Last reply Reply Quote 1
        • M
          mp5gosu
          last edited by

          Hey Riccardo,

          Sorry for not being precise.
          I'm talking about the new Maxon API and its data containers, not the classic API at all.
          As far as I understand the maxon::DataDictionary and maxon::Data types, they are the replacements for both legacy types, BaseContainer and GeData.
          Now I wanted to have a class being a registered as a new Data type as written here, so I can use it with a DataDictionary

          However, I want the type to be initialized with a certain value. Let me illustrate it on the SDK example:

          // This example defines a custom class and declares it as a MAXON data type.
          #include "maxon/datatype.h"
          #include "maxon/string.h"
          // ------------------------------
          // Triplet of maxon::Int values.
          // ------------------------------
          class IntegerTriplet
          {
          maxon::Int _val; // Keep it private
          
          public:
            explicit IntegerTriplet(const maxon::Int val) : _val(val) {} // This gives a compiler error, complaining about that there's no default constructor available.
          };
          // register as MAXON data type
          MAXON_DATATYPE(IntegerTriplet, "net.maxonexample.datatype.integertriplet"); 
          

          And usage:

          IntegerTriplet triplet(30);
          // ...
          

          Can be that I misunderstood the concept of the new MAXON Data types, and I'd be really thankful if you can shed some light onto this.

          1 Reply Last reply Reply Quote 0
          • r_giganteR
            r_gigante
            last edited by

            @mp5gosu said in MAXON Data Type and explicit constructors:

            // This gives a compiler error, complaining about that there's no default constructor available.

            As suggested by the compiler simply make the default constructor living beside your constructor and the compiler won't complain anymore 🙂

            class IntegerTriplet
            {
            private:
              maxon::Int _val;
            
            public:
              IntegerTriplet(){}
              explicit IntegerTriplet(const maxon::Int val) : _val(val) {} 
            };
            

            Cheers, Riccardo

            1 Reply Last reply Reply Quote 2
            • M
              mp5gosu
              last edited by mp5gosu

              Of course, but doesn't this make the explicit constructor useless? With that approach the user is still able to instantiate the class without initializing the variable on creation correctly.

              At least when testing this, I was able to instatntiate the class without the need for an argument, so I assume that the explicit constructor simply gets omitted.

              1 Reply Last reply Reply Quote 0
              • r_giganteR
                r_gigante
                last edited by r_gigante

                Hi mp5gosu, thanks for following up.

                I see your point, but actually you can still initialize the member variables to a "reasonable" default value helping to identify cases when the class was instantiated without any explicit value.

                A final, additional, side note about initialization: considering that constructors can't return any "evidence" of failure when allocating members we advise against initializing members directly in the constructor.
                We rather suggest implementing an additional Init() method where the members' initialization takes place as shown in the code snippet in the Entity Creation section.

                Best, Riccardo

                1 Reply Last reply Reply Quote 4
                • M
                  mp5gosu
                  last edited by

                  Thanks Riccardo!

                  Now I understand - thanks to your side note. 🙂
                  And of course I understand, that this goes hand in hand with your guidelines.

                  Cheers,
                  Robert

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