BaseContainer and range-based loop



  • Say I am using a BaseContainer to hold a list of Int32 values, I know there exists a BrowseContainer to loop over the content of the BaseContainer's entries.
    But what if I would prefer to use a range-based for-loop for this, how would I go about this?

    I know there are BaseArray or BaseList or even HashMap which would be preferred in order to provide for a native range-based for-loop (as well as native iterator support).

    But let's assume these types don't cut it, and that the BaseContainer is the better approach for holding the data. How would one go about implementing range-based support (or iterator support in general) for this?



  • Hi @C4DS thanks for reaching out us.

    Just to be sure we're on the same page: are you referring to this, right?

    Cheers, Riccardo



  • @r_gigante
    Yes, indeed.
    I already had a look into the technicals for a range-based for-loop, and it requires a begin() and end() method. Both of these would then be related to a pointer to the data.
    Constructing an own custom type or storage-container, I could see myself making use of an allocated block of memory and storing the data in that, allowing to work with the pointer.
    However, for a BaseContainer I don't see any way to interact with its internals.
    The only pointers that can be obtained are GeData* to specific entries (via const GeData* GetDataPointer(Int32 id) const), but that obviously doesn't provide the appropriate pointers to allow begin() and end() to work with.

    I am also looking into extending the functionality of an HashMap, and in both cases I would use the storage (HashMap or BaseContainer) as a data container, encapsulated in my custom " list" type.

    So, in general I am looking for a way to have custom storage containers (e.g. Int32UniqueList, Int32Set, ...) using Int32, Float, Bool, ... as type, but with other functionality than available with the BaseArray, BaseList, HashMap, SortedArray, .... Still being able to iterate over these via index, iterator and range-base.
    And, as such, as a start, I am looking into the possibilities with BaseContainer.

    As the documentation mentions that "base" in BaseArray isn't an indication that one should derive from it, I am looking for possibilities to:

    • or encapsulate the storage-type into a custom list-type
    • or indeed derive from it and provide additional functionality

    I hope I haven't confused you more than I have provided answers.



  • hello,

    I've tried several possibilities but for all of them you need to know how much ID you have and what they are. (doesn't help that much)

    You need to store your data (and maybe your custom data), did you have a look at DataDictionary or other possibilities

    Cheers
    Manuel



  • @m_magalhaes
    During all those years since R17 I must have continuously overlooked the maxon::Data and maxon::DataDictionary ...
    Thanks for pointing these out to me!

    I am embarrassed to admit having missed these while browsing and searching through the SDK documentation, over and over again.



  • Make sense, because it's available since R20 ^^



  • @m_magalhaes
    Ah!
    However, I had preferred it was me who had overlooked these all those years. As this means I will still need to find a different solution for pre-R20 compatibility.