The C++ Array Class

The Array class is provided for handling arrays of Values.

For an overview see page C++ Classes

Note that Array inherits from List which implements methods common to Arrays and Strings.

The Array methods are listed below.

McoSql::ValueRef getAt( size_t index )

Return a reference to the Value object at index. (Note that, if the application gets a reference to an object, and this object is deallocated (perhaps along with its parent array), the reference becomes invalid. In this case the user should obtain a copy of the object using getCopyAt()(see below) instead of the reference.

McoSql::Value *getCopyAt( size_t index )
Return a copy of the object at index. Note that the difference between getAt() and getCopyAt() is that getAt() returns a reference (ValueRef) to the element in the array, while getCopyAt() returns a copy of the element. When using getCopyAt(), the application is responsible for explicitly freeing (deallocating) the copy. For example:
 
  // Get a copy of the object at index 0
  McoSql::Value *v = array->getCopyAt(0);
   
  // Use the object...
   
  // Explicitly destroy the copy to avoid memory leak
  v->destroy(&allocator);
 
void setAt( size_t index, McoSql::Value* value)
Set the array element at position index to value
Value * updateAt( int index )
Get the structure or array element with the specified index for update; returns the Value of the element with the specified index whose components or elements will be updated
size_t size();
Return the number of elements in the allocated array
void setSize(size_t newSize);
Set the number of elements in the array to operate on. Note that the specified size must not exceed the size of the allocated array (returned by method size()) and it is necessary to later restore it to the original value (by calling again method setSize()) after the desired operation is completed; otherwise deallocation will be performed incorrectly
void getBody( void * dst, size_t offs, size_t len )
Copy the specified number of elements len from the array body to the buffer dst. (Note that this method can be used only for arrays of scalar types)
void setBody( void * src, size_t offs, size_t len )
Set the specified number of elements len from the buffer src to the array body (Note that this method can be used only for arrays of scalar types)
size_t getElemSize( void )
Return the size in bytes of an array element
McoSql::Type getElemType()
Return the type of the type of the array elements
size_t toString( char * buf , size_t & size )
Serialize the current Value to the specified buffer. Only size bytes are copied (Note that if the terminating null does not fit in size bytes, the resulting buffer will NOT be null-terminated)
Value * clone( McoSql::Allocator* allocator )
Create a copy of the array using the specified memory allocator
Array * makeNullable()
Return the underlying value array as a NullableArray