MStringArray Class Reference

#include <MStringArray.h>

Class Description

Array of MStrings data type.

This class implements an array of MStrings. Common convenience functions are available, and the implementation is compatible with the internal Maya implementation so that it can be passed efficiently between plugins and internal maya data structures.

+ Examples:

Public Member Functions

 MStringArray ()
 Default constructor. More...
 
 MStringArray (const MStringArray &other)
 Copy constructor. More...
 
 MStringArray (const MString strings[], unsigned int count)
 Create a new array of MStrings and initialize it with the given elements. More...
 
 MStringArray (const char *strings[], unsigned int count)
 Create a new array of MStrings and initialize it with the given elements. More...
 
 MStringArray (unsigned int initialSize, const MString &initialValue)
 Create a new array of strings of a specified size and initialize all the elements with the given initial value. More...
 
 ~MStringArray ()
 The class destructor.
 
MString operator[] (unsigned int index) const
 Index operator. More...
 
MStringArrayoperator= (const MStringArray &other)
 Assignment operator copies all of the elements of the other array into this one. More...
 
MStatus set (const MString &element, unsigned int index)
 Sets the value of the indicated element to the indicated value. More...
 
MStatus set (char *element, unsigned int index)
 Sets the value of the indicated element to the indicated char* value. More...
 
MStatus setLength (unsigned int length)
 Set the length of the array. More...
 
unsigned int length () const
 Returns the number of elements in the instance. More...
 
MStatus remove (unsigned int index)
 Remove the array element at the given index. More...
 
MStatus insert (const MString &element, unsigned int index)
 Inserts a new value into the array at the given index. More...
 
MStatus append (const MString &element)
 Adds a new element to the end of the array. More...
 
MStatus clear ()
 Clear the contents of the array. More...
 
MStatus get (MString array[]) const
 Copy the elements of the array into the array of MStrings. More...
 
MStatus get (char *array[]) const
 Copy the elements of the array into the C++ array of character pointers. More...
 
int indexOf (const MString &element) const
 Get the location of the string in the array. More...
 
void setSizeIncrement (unsigned int newIncrement)
 Set the size by which the array will be expanded whenever expansion is necessary. More...
 
unsigned int sizeIncrement () const
 Return the size by which the array will be expanded whenever expansion is necessary. More...
 
MStringoperator[] (unsigned int index)
 NO SCRIPT SUPPORT. More...
 

Static Public Member Functions

static const char * className ()
 Returns the name of this class. More...
 

Friends

OPENMAYA_EXPORT std::ostream & operator<< (std::ostream &os, const MStringArray &array)
 NO SCRIPT SUPPORT. More...
 

Constructor & Destructor Documentation

Default constructor.

The instance is set to contain no elements.

MStringArray ( const MStringArray other)

Copy constructor.

Parameters
[in]otherthe array with which to initialize this instance
MStringArray ( const MString  src[],
unsigned int  count 
)

Create a new array of MStrings and initialize it with the given elements.

Parameters
[in]srcan array of MStrings
[in]countthe number of elements in the src array
MStringArray ( const char *  src[],
unsigned int  count 
)

Create a new array of MStrings and initialize it with the given elements.

The MStringArray object then owns the character strings and it is responsible for freeing them. The user is responsible for freeing the original array of pointers to type char.

Parameters
[in]srca C++ array of character pointers
[in]countthe number of elements in the array
MStringArray ( unsigned int  initialSize,
const MString initialValue 
)

Create a new array of strings of a specified size and initialize all the elements with the given initial value.

Parameters
[in]initialSizethe initial size of the array
[in]initialValuethe initial value of each element

Member Function Documentation

MString operator[] ( unsigned int  index) const

Index operator.

Returns the value of the element at the given index. If the index is out of the range 0 - length()-1, returns a NULL string.

Parameters
[in]indexthe index of the element whose value is to be returned
Returns
The value of the indicated element.
MStringArray & operator= ( const MStringArray other)

Assignment operator copies all of the elements of the other array into this one.

If the other array was returned as a reference to internal data (eg MFnStringArrayData::array), then this array will also become a reference rather than doing a full copy.

Parameters
[in]otherthe array being copied
Returns
A reference to this array
MStatus set ( const MString element,
unsigned int  index 
)

Sets the value of the indicated element to the indicated value.

Parameters
[in]elementthe new value for the indicated element
[in]indexthe index of the element that is to be set to the the new value
Returns
+ Examples:
MStatus set ( char *  element,
unsigned int  index 
)

Sets the value of the indicated element to the indicated char* value.

Parameters
[in]elementthe new value for the indicated element
[in]indexthe index of the element that is to be set to the the new value
Returns
MStatus setLength ( unsigned int  length)

Set the length of the array.

This will grow and shrink the array as desired. Elements that are grown have uninitialized values, while those which are shrunk will lose the data contained in the deleted elements (ie. it will release the memory).

Parameters
[in]lengththe new size of the array
+ Examples:
unsigned int length ( ) const

Returns the number of elements in the instance.

Returns
The number of elements in the instance
+ Examples:
MStatus remove ( unsigned int  index)

Remove the array element at the given index.

All array elements following the removed element are shifted toward the first element.

Parameters
[in]indexindex of the element to be removed
Returns
+ Examples:
MStatus insert ( const MString element,
unsigned int  index 
)

Inserts a new value into the array at the given index.

The initial element at that index, and all following elements, are shifted towards the last. If the array cannot be expanded in size by 1 element, then the insert will fail and the existing array will remain unchanged.

Parameters
[in]elementthe new value to insert into the array
[in]indexthe index of the element to set to the the new value
Returns
MS::kSuccess if the insert was successful and MS::kFailure otherwise
+ Examples:
MStatus append ( const MString element)

Adds a new element to the end of the array.

If the array cannot be expanded in size by 1 element, then the append will fail and the existing array will remain unchanged.

Parameters
[in]elementthe value for the new last element
Returns
MS::kSuccess if the append was successful and MS::kFailure otherwise
+ Examples:
MStatus get ( MString  array[]) const

Copy the elements of the array into the array of MStrings.

No checking is done to ensure that the destination array of MStrings is large enough to hold all the elements of the instance.

Parameters
[out]arraythe array to populate
Returns
MS::kSuccess if the array argument is a non-zero pointer and MS::kFailure otherwise
+ Examples:
MStatus get ( char *  array[]) const

Copy the elements of the array into the C++ array of character pointers.

No checking is done to ensure that the destination C++ array of character pointers is large enough to hold all the elements of the instance.

Parameters
[out]arraythe array to populate
Returns
MS::kSuccess if the array argument is a non-zero pointer and MS::kFailure otherwise
int indexOf ( const MString element) const

Get the location of the string in the array.

Parameters
[in]elementthe string to locate
Returns
the index of the first occurrence of the string in the array or -1 if not found.
void setSizeIncrement ( unsigned int  newIncrement)

Set the size by which the array will be expanded whenever expansion is necessary.

Parameters
[in]newIncrementthe new increment
unsigned int sizeIncrement ( ) const

Return the size by which the array will be expanded whenever expansion is necessary.

Returns
The size increment.
MString & operator[] ( unsigned int  index)

NO SCRIPT SUPPORT.

Index operator allowing assignment to an element of the array.

Returns a reference to the element at the given index. If the index is outside the range 0 - length()-1, returns a NULL string.

Parameters
[in]indexthe index of the desired element
Returns
A reference to the indicated element
const char * className ( )
static

Returns the name of this class.

Returns
The name of this class.

Friends And Related Function Documentation

OPENMAYA_EXPORT std::ostream& operator<< ( std::ostream &  os,
const MStringArray array 
)
friend

NO SCRIPT SUPPORT.

The format used is ["string", "string", "string", ... "string"].

Parameters
[in]osthe ostream to print to
[in]arraythe MStringArray whose value is to be printed
Returns
The ostream reference, s, provided as the first parameter.

The documentation for this class was generated from the following files:
  • MStringArray.h
  • MStringArray.cpp