Google APIs Client Library for C++
JsonCppArray< T > Class Template Reference

Base class template for a JsonCppData object that is an array. More...

#include "client/data/jsoncpp_data.h"

+ Inheritance diagram for JsonCppArray< T >:

List of all members.

Public Types

typedef
JsonCppConstIndexIterator< T > 
const_iterator

Public Member Functions

 JsonCppArray (const Json::Value &value)
 Standard constructor for an immutable array.
 JsonCppArray (Json::Value *value)
 Standard constructor for a mutable array.
bool empty () const
 Determines if array is empty or not.
int size () const
 Determines the number of elements currently in the array.
const Json::Value & as_value (int i) const
 Gets the [immutable] underlying JsonCpp storage for a given array element.
Json::Value * as_mutable_value (int i)
 Gets the [mutable] underlying JsonCpp storage for a given array element.
const JsonCppData as_object (int i) const
 Gets the [immutable] JsonCppData instance wrapping a given array element.
JsonCppData as_mutable_object (int i)
 Gets the [mutable] JsonCppData instance wrapping a given array element.
const_iterator begin () const
 Returns the starting point for iterating over the elements.
const_iterator end () const
 Returns the ending poitn when iterating over the elements.
void set (int i, const T &value)
 Changes the value for the given element.
const T get (int i) const
 Returns the value for the given index.
mutable_get (int i)
 Returns a mutable value for the given index.
const T operator[] (int i) const
 Provides syntactic sugar for get using [] operator overloading.
operator[] (int i)
 Provides syntactic sugar for mutable_get using [] operator overloading.
void Import (const vector< T > &array)
 Imports data from a C++ vector into this instance.
void Import (const T *array, int len)
 Imports data from a C++ aray into this instance.
void Export (vector< T > *array) const
 Exports data from this instance into a given C++ vector.
bool Export (int offset, int count, vector< T > *array) const
 Exports a range of data from this instance into a given C++ vector.
bool Export (int offset, int count, T *array) const
 Exports a range of data from this instance into a given C++ array.

Detailed Description

template<typename T>
class googleapis::client::JsonCppArray< T >

Base class template for a JsonCppData object that is an array.

Arrays currently follow the JsonCpp implementation where they grow on demand. Accessing an element wil create it if it did not already exist.

This class is not thread-safe.

Todo:
(ewiseblatt): 20120825 Probably change this so the arrays are fixed size unless you resize the array or append/remove from it. That means get/set should rangecheck.

Member Typedef Documentation


Constructor & Destructor Documentation

JsonCppArray ( const Json::Value &  value) [inline, explicit]

Standard constructor for an immutable array.

Parameters:
[in]valueProvides the underlying storage for the array.
JsonCppArray ( Json::Value *  value) [inline, explicit]

Standard constructor for a mutable array.

Parameters:
[in]valueProvides the underlying storage for the array.

Member Function Documentation

JsonCppData as_mutable_object ( int  i) [inline]

Gets the [mutable] JsonCppData instance wrapping a given array element.

See also:
as_mutable_value
mutable_get
Json::Value* as_mutable_value ( int  i) [inline]

Gets the [mutable] underlying JsonCpp storage for a given array element.

This method will CHECK fail if the array is not mutable.

See also:
as_mutable_object
mutable_get
const JsonCppData as_object ( int  i) const [inline]

Gets the [immutable] JsonCppData instance wrapping a given array element.

See also:
as_value
get
const Json::Value& as_value ( int  i) const [inline]

Gets the [immutable] underlying JsonCpp storage for a given array element.

See also:
as_object
get
const_iterator begin ( ) const [inline]

Returns the starting point for iterating over the elements.

Unfortunately this data model only permits const iterators because of the call-by-value-result nature of the api. We cant modify the elements unless we create a storage iterator that iterates over the storage (which you can already do by saying MutableStorage()->begin/end()

bool empty ( ) const [inline]

Determines if array is empty or not.

const_iterator end ( ) const [inline]

Returns the ending poitn when iterating over the elements.

void Export ( vector< T > *  array) const [inline]

Exports data from this instance into a given C++ vector.

This will clear the array before exporting.

bool Export ( int  offset,
int  count,
vector< T > *  array 
) const [inline]

Exports a range of data from this instance into a given C++ vector.

This will clear the array before exporting.

Parameters:
[in]offsetThe first index in this array to eport
[in]countThe number of elements to export
[out]arrayThe array to write to will be cleared before writing. The element at offset will be written into the 0'th element.
Returns:
false if the existing bounds of this array are not consistent with the arguments.
bool Export ( int  offset,
int  count,
T *  array 
) const [inline]

Exports a range of data from this instance into a given C++ array.

Parameters:
[in]offsetThe first index in this array to eport
[in]countThe number of elements to export
[out]arrayThe caller should ensure that there are count elements allocated in the array.
Returns:
false if the existing bounds of this array are not consistent with the arguments.
const T get ( int  i) const [inline]

Returns the value for the given index.

Parameters:
[in]iThe element index to get.
void Import ( const vector< T > &  array) [inline]

Imports data from a C++ vector into this instance.

This method will clear the current data before importing the new.

Parameters:
[in]arrayThe vector to import from.
void Import ( const T *  array,
int  len 
) [inline]

Imports data from a C++ aray into this instance.

This method will clear the current data before importing the new.

Parameters:
[in]arrayThe array to import from.
[in]lenThe number of elements int he array to import.
T mutable_get ( int  i) [inline]

Returns a mutable value for the given index.

This method will CHECK-fail if the array is not mutable.

Returns:
The value as opposed to a pointer. See the class description for more information about the calling conventions. Although the value is not a pointer, it will be mutable if T denotes a JsonCppObject. For primitive types (and strings) this method will return copy that will not actually mutate the underlying element.
const T operator[] ( int  i) const [inline]

Provides syntactic sugar for get using [] operator overloading.

T operator[] ( int  i) [inline]

Provides syntactic sugar for mutable_get using [] operator overloading.

void set ( int  i,
const T &  value 
) [inline]

Changes the value for the given element.

This method will CHECK-fail if the array is not mutable.

Parameters:
[in]iThe index to change will be added if it was not present.
[in]valueThe value to copy.
int size ( ) const [inline]

Determines the number of elements currently in the array.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines