jvar
JS inspired Variant and Json
jvar::StrArray Class Reference

Detailed Description

StrArray is an array of character strings and maintains them in sorted order

#include <arr.h>

+ Inheritance diagram for jvar::StrArray:
+ Collaboration diagram for jvar::StrArray:

Public Types

enum  { FLAG_FIXEDBUF = 0x1 }
typedef int(* Compare )(const void *, const void *)

Public Member Functions

std::string * add (const char *keyelem)
bool remove (const char *keyelem)
std::string * find (const char *elem)
std::string * insert (int pos)
void * insert (int pos, const void *elem)
std::string * insertCustom (int pos)
std::string * append ()
void * append (const void *elem)
std::string * addOrModify (const std::string *keyelem, bool modifyfound=true)
void * addOrModify (const void *elem, bool modifyfound=true)
std::string * add (const std::string *keyelem)
void * add (const void *elem)
bool remove (const std::string *keyelem)
bool remove (int pos)
bool remove (const void *elem)
std::string * find (const std::string *elem)
void * find (const void *elem)
std::string * get (int pos)
bool forEach (Iter< std::string > &iter)
bool forEachReverse (Iter< std::string > &iter)
void useFixedMem (void *memptr, int *countptr, int maxlen)
void clear ()
int length ()
bool full ()
void sort (Compare comp=NULL)
bool findPos (const void *findelem, int &pos)
void reserve (int elemcount)

Static Public Member Functions

static int compare (const void *e1, const void *e2)

Public Attributes

uint mFlags

Protected Member Functions

void copyFrom (BArray &src, bool alloconly, bool move)
bool binSearch (const void *findelem, int &pos)
void ensureAlloc (int desiredlen)

Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
FLAG_FIXEDBUF 

Array is currently using fixed buffer provided via useFixedMemory


Member Function Documentation

void* jvar::BArray::add ( const void *  elem) [inline, inherited]

Adds an element in order using the compare function

Parameters:
elemPointer to the element which will be copied
Returns:
Pointer to the element in array

References jvar::BArray::addOrModify().

std::string * jvar::ObjArray< std::string >::add ( const std::string *  keyelem) [inline, inherited]

Adds an item based to the array keeping it sorted

Parameters:
keyelemElement to add
Returns:
Pointer to the added or modifed element
std::string* jvar::StrArray::add ( const char *  keyelem) [inline]

Adds a string to the array

Parameters:
keyelemString to add
Returns:
Pointer to the stl::string element
void * jvar::BArray::addOrModify ( const void *  elem,
bool  modifyfound = true 
) [inherited]

Adds an element or modifies it if it already exists

Parameters:
elemPointer to element which will be copied
modifyfoundShould it be modified (true=allow, false=don't allow)
Returns:
Pointer to the element in array

References jvar::BArray::insert().

Referenced by jvar::BArray::add().

std::string * jvar::ObjArray< std::string >::addOrModify ( const std::string *  keyelem,
bool  modifyfound = true 
) [inline, inherited]

Adds a new element or modifies it if exists.

Parameters:
keyelemElement to search and add if doesn't exist or modify
modifyfoundAllow modifying the lement
Returns:
Pointer to the added or modified element
void* jvar::BArray::append ( const void *  elem) [inline, inherited]

Appends or adds an element at the end of the array

Parameters:
elemPointer to the element which will be copied
Returns:
Pointer to the element in array

References jvar::BArray::insert(), and jvar::BArray::length().

Referenced by jvar::ObjArray< int >::append().

std::string * jvar::ObjArray< std::string >::append ( ) [inline, inherited]

Appends a new element at the end of the array

Returns:
Pointer to the newly created element
void jvar::BArray::clear ( ) [inherited]
void * jvar::BArray::find ( const void *  elem) [inherited]

Finds an element in array that matches the provided element

Parameters:
elemPointer to an element to search
Returns:
Pointer to the element in array
std::string * jvar::ObjArray< std::string >::find ( const std::string *  elem) [inline, inherited]

Finds the item

Parameters:
elemElement to find (only the key is used)
Returns:
Pointer to the element
std::string* jvar::StrArray::find ( const char *  elem) [inline]

Finds a string in the array

Parameters:
elemString to find
Returns:
Pointer to the stl::string element or NULL
bool jvar::BArray::findPos ( const void *  findelem,
int &  pos 
) [inline, inherited]

Finds the position of an element

Parameters:
findelemPointer to an element to search
posReturns the position of the found element
Returns:
True if found, false otherwise
bool jvar::ObjArray< std::string >::forEach ( Iter< std::string > &  iter) [inline, inherited]

Returns an iterator to go over elements of the array in order

Parameters:
iterIterator
Returns:
Success
bool jvar::ObjArray< std::string >::forEachReverse ( Iter< std::string > &  iter) [inline, inherited]

Returns an iterator go over elements in reverse order

Parameters:
iterIterator
Returns:
Success
bool jvar::BArray::full ( ) [inline, inherited]

Determines if the array is at capacity.

Returns:
True if full, false otherwise

Referenced by jvar::BArray::insert().

std::string * jvar::ObjArray< std::string >::get ( int  pos) [inline, inherited]

Returns an element from the array

Parameters:
posPosition of retrieve the element
Returns:
Pointer to the element

Reimplemented from jvar::BArray.

void * jvar::BArray::insert ( int  pos,
const void *  elem 
) [inherited]

Insert an element into the array

Parameters:
posPosition to insert at
elemPointer to element which will be copied

References jvar::BArray::FLAG_FIXEDBUF, jvar::BArray::full(), jvar::BArray::length(), and jvar::BArray::mFlags.

Referenced by jvar::BArray::addOrModify(), jvar::ObjArray< int >::addOrModify(), jvar::BArray::append(), and jvar::ObjArray< int >::insert().

std::string * jvar::ObjArray< std::string >::insert ( int  pos) [inline, inherited]

Inserts a new element at the provided position in the array

Parameters:
posPosition to insert
Returns:
Pointer to the newly created element
std::string * jvar::ObjArray< std::string >::insertCustom ( int  pos) [inline, inherited]

Inserts an element at the provided position in the array. The new element is not constructed by ths call. The caller uses "inplace new" to call a non-default constructor.

Parameters:
posPosition to insert
Returns:
Pointer to the inserted element
bool jvar::BArray::remove ( const void *  elem) [inherited]

Removes an element from array that matches the provided element

Parameters:
elemPointer to an element to search
Returns:
Success
bool jvar::ObjArray< std::string >::remove ( const std::string *  keyelem) [inline, inherited]

Removes an item using a key

Parameters:
keyelemElement to remove (only key is used)
Returns:
Success
bool jvar::ObjArray< std::string >::remove ( int  pos) [inline, inherited]

Removes an element from the provided position

Parameters:
posPosition to remove the item
Returns:
Success

Reimplemented from jvar::BArray.

bool jvar::StrArray::remove ( const char *  keyelem) [inline]

Removes a string from the array

Parameters:
keyelemString to remove
Returns:
Success
void jvar::BArray::reserve ( int  elemcount) [inline, inherited]

Ensures that the array has at least the specified allocation

Parameters:
elemcountNumber of element to reserve
void jvar::BArray::sort ( Compare  comp = NULL) [inline, inherited]

Sorts the array

Parameters:
compCompare function (if NULL, the one from constructor is used)
void jvar::BArray::useFixedMem ( void *  memptr,
int *  countptr,
int  maxlen 
) [inherited]

Enters fixed memory mode using the provided memory

Parameters:
memptrPointer to allocated fixed memory
countptrPointer to a variable where current count is held
maxlenMaximum number of elements (size specified in constructor)

References jvar::BArray::FLAG_FIXEDBUF, jvar::Buffer::free(), and jvar::BArray::mFlags.


Member Data Documentation


The documentation for this class was generated from the following file:
 All Classes Functions Variables Enumerator