In the Maya SDK array container classes which are

  • MIntArray
  • MFloatArray
  • MDoubleArray
  • MVectorArray
  • MPointArray
  • MFloatPointArray
  • MFloatVectorArray
  • MCallbackIdArray
  • MAttributeSpecArray
  • MColorArray
  • MDagPathArray
  • MMatrixArray
  • MRenderLineArray
  • MTimeArray
  • MTrimBoundaryArray
  • MUint64Array

has got an entirely different interface compared to the stl conatiner classes. They dont expose any iterator interface. Consequently we cannot use the data contained in them in stl or generic algorithms.

So we have come up with a templatized wrapper class MArray_stl. A wrapper class for MFloatVectorArray would be defined as

typedef kg::MArray_stl< float, MFloatVector, MFloatVectorArray > MArray_stl_fv;

The code can be found here which is tested to work for Maya8.5.

Since the container classes that we wrap are not light weight classes and carry heavy data, the wrapper class just maintains a pointer to the allready constructed maya container class. For example an instance of MArray_stl_fv would maintain a pointer to the MFloatVectorAray that it is pointing to.

MFloatVectorArray fa; //populate this float vector array and use it for something. typedef typename kg::MArray_stl kgWrapper; kgWrapper kg_fa( fa ); //do some generic programming code with kg_fa Here are the differences of the MArray_stl class compared with std::vector.

  • The only constructors to the wrapper class include a copy constructor, and a constructor that accepts a reference to the maya container class. We don't allow a default constructor for MArray_stl, since it mean that the wrapper class MArray_stl would have to carry a NULL pointer to the corresponding container class. If it carries a NULL pointer, then what would begin and end iterators be?
  • since Maya container classes doesn't expose any reserve functionality, the reserve function of the wrapper class doesn't do anything. Also the capacity function just returns the length of the container.
  • The allocator member variable doesn't perform any functionality and is a dummy value.
  • Also, use the copy constructor and assignment operator with caution, the use of which leads to two wrappers pointing to the same wrapee.

The core header file where this is referenced can be found at here

blog comments powered by Disqus