Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    BaseArray Question

    SDK Help
    0
    3
    324
    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.
    • H
      Helper
      last edited by

      On 09/09/2013 at 13:17, xxxxxxxx wrote:

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

      ---------
      Hello, I recently switched over to sing R14 because of Jack's post about how much faster BaseArray was than GeDynamicArray.  Anyway, I might be totally wrong, but I've been trying to use GetIndex() to find the location of elements in the array and it always returns not found.  From what the SDK says and trying to figure it out myself, it looks like it can only find the location if I use the array entry in GetIndex(), otherwise it always returns -1.

        
      c4d_misc::BaseArray<LONG> test;  
      test.Append(0);  
      test.Append(1);  
      test.Append(2);  
      test.Append(3);  
      test.GetIndex(2); // returns -1  
      test.GetIndex(test[2]);  //so it's still looking for "2" and it correctly returns 2 this time  
      

      It seems like you could only use GetIndex() if you already knew what location of the element you're  looking for.  I'm sure I'm wrong but I can't find a way around it and would appreciate any help.

      Thanks, Daniel

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 09/09/2013 at 13:45, xxxxxxxx wrote:

        Read the description carefully:

        Int GetIndex(const T & x) const [inline]

        Gets the index of the element.

        The element must be part of the array, otherwise (e.g. if x is a copy of an array element) InvalidArrayIndex will be returned.

        Returns:
        index of element or InvalidArrayIndex (not element of this)

        The function returns the index of the passed array element. If you just pass "2" to the function, it can't work. What should happen if multiple elements contain "2" ?

        GetIndex comes in handy when you use an Iterator or AutoIterator.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 09/09/2013 at 14:11, xxxxxxxx wrote:

          Thanks Jack, that makes sense reading it again, I think I understand.   I'm looking for a Find type function like in GeDynamicArray and I thought that was it. Is there such a thing in BaseArray?  If not is there a way of going about it?  Do I need to use a SortedArray?

          Edit:  A little late, nevermind I'm silly.  You just use BaseSort to do it.

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