Rudiments
Public Member Functions | List of all members
collection Class Referenceabstract

Inherits object.

Inherited by arraycollection< valuetype >, dictionarycollection< keytype, valuetype >, dom, nodecollection< valuetype >, scalarcollection< valuetype >, and tablecollection< valuetype >.

Public Member Functions

 collection ()
 
 collection (collection &c)
 
collectionoperator= (collection &c)
 
virtual ~collection ()
 
virtual const char * getType ()=0
 
virtual uint64_t getCount ()=0
 
comparatorgetComparator ()
 
void setComparator (comparator *newcomp)
 
virtual bool isReadOnly ()
 
virtual bool isBlockBased ()
 
virtual uint64_t getBlockSize ()
 
virtual bool isSequentialAccess ()
 
virtual void setManageValues (bool manage)
 
virtual bool getManageValues ()
 
virtual void setManageArrayValues (bool manage)
 
virtual bool getManageArrayValues ()
 
virtual void setManageKeys (bool manage)
 
virtual bool getManageKeys ()
 
virtual void setManageArrayKeys (bool manage)
 
virtual bool getManageArrayKeys ()
 
virtual bool clear ()=0
 
virtual ssize_t write ()=0
 
virtual ssize_t write (output *out)=0
 
virtual ssize_t writeJson ()=0
 
virtual ssize_t writeJson (bool indent)=0
 
virtual ssize_t writeJson (output *out)=0
 
virtual ssize_t writeJson (output *out, bool indent)=0
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

The collection class is the parent class for all rudiments collections.

Constructor & Destructor Documentation

◆ collection() [1/2]

collection::collection ( )
inline

Creates an instance of the collection class.

◆ collection() [2/2]

collection::collection ( collection c)
inline

Creates an instance of the collection class that is a copy of "c".

◆ ~collection()

collection::~collection ( )
inlinevirtual

Deletes this instance of the collection class.

Member Function Documentation

◆ clear()

virtual bool collection::clear ( )
pure virtual

◆ getBlockSize()

uint64_t collection::getBlockSize ( )
inlinevirtual

Returns the block size for block-based implementations and 0 for monolithic implementations.

Returns 0 by default.

◆ getComparator()

comparator * collection::getComparator ( )
inline

Returns the comparator used internally by the class. Returns whatever was previously set by setComparator() or an instance of the comparator class by default.

◆ getCount()

virtual uint64_t collection::getCount ( )
pure virtual

◆ getManageArrayKeys()

bool collection::getManageArrayKeys ( )
inlinevirtual

Returns whether or not this instance of the collection class is configured to manage the arrays that are stored as the keys at each location in the collection.

See setManageArrayValues().

Returns true if it is and false if it is not.

◆ getManageArrayValues()

bool collection::getManageArrayValues ( )
inlinevirtual

Returns whether or not this instance of the collection class is configured to manage the arrays that are stored as the values at each location in the collection.

See setManageArrayValues().

Returns true if it is and false if it is not.

Reimplemented in table< valuetype >.

◆ getManageKeys()

bool collection::getManageKeys ( )
inlinevirtual

Returns whether or not this instance of the collection class is configured to manage the objects that are stored as the keys at each location in the collection.

See setManageKeys().

Returns true if it is and false if it is not.

◆ getManageValues()

bool collection::getManageValues ( )
inlinevirtual

Returns whether or not this instance of the collection class is configured to manage the objects that are stored as the values at each location in the collection.

See setManageValues().

Returns true if it is and false if it is not.

Reimplemented in table< valuetype >.

◆ getType()

virtual const char* collection::getType ( )
pure virtual

◆ isBlockBased()

bool collection::isBlockBased ( )
inlinevirtual

Returns true for block-based implementations and false for monolithic implementations.

Returns false by default.

◆ isReadOnly()

bool collection::isReadOnly ( )
inlinevirtual

Returns true for read-only implementations and false for read-write implementations.

Returns false by default.

◆ isSequentialAccess()

bool collection::isSequentialAccess ( )
inlinevirtual

Returns true for sequential-access implementations and false for random-access implementations.

Returns false by default.

◆ operator=()

collection & collection::operator= ( collection c)
inline

Makes this instance of the collection class identical to "c".

◆ setComparator()

void collection::setComparator ( comparator newcomp)
inline

Sets the comparator used by the class. Reverts to the default comparator if "newcomp" is NULL.

◆ setManageArrayKeys()

void collection::setManageArrayKeys ( bool  manage)
inlinevirtual

Indicates whether or not this instance should "manage" the keys that are stored at each location in the collection as arrays.

"manage" should only be set true if the keys stored in the collections are pointers to arrays of primitive types.

Defaults to "false".

If "manage" is set to true then:

  • When remove() is called, the array stored as the key at that location in the collection will be array-deleted.
  • When clear() is called, the array stored as the key at each location in the collection will be array-deleted.
  • When the = operator is called, the lvalue instance will attempt to create a copy of the array stored as the key in each location of the rvalue instance.
  • When the copy constructor is called, the new instance will attempt to create a copy of the array stored as the key in each location of the instance that is being copied.

If "manage" is set to false then:

  • When remove() is called, the array stored as the key at that location in the collection will not be array-deleted.
  • When clear() is called, the array stored as the key at each location in the collection will not be array-deleted.
  • When the = operator is called, the lvalue instance will not attempt to create a copy of the array stored as the key in each location of the rvalue instance, rather it will just copy the value or pointer.
  • When the copy constructor is called, the new instance will not attempt to create a copy of the array stored as the key in each location of the instance that is being copied, rather it will just copy the value or pointer.

To store managed arrays of non-primitive types as keys, consider using a managed collection of managed staticarrays. For example:

    dictionary<staticarray< myobject * > *,
                                    uint32_t >      d;
    d.setManageKeys(true);

    staticarray< myobject * >       *s1=
                    new staticarray< myobject * >();
    s1.setManageKeys(true);
    s1[0]=new myobject(...);
    s1[1]=new myobject(...);
    s1[2]=new myobject(...);
    d.setValue(s1,1);

    staticarray< myobject * >       *s2=
                    new staticarray< myobject * >();
    s2.setManageKeys(true);
    s2[0]=new myobject(...);
    s2[1]=new myobject(...);
    s2[2]=new myobject(...);
    d.setValue(s2,2);

    ...

Note that setting this true implies setManageKeys(false);

◆ setManageArrayValues()

void collection::setManageArrayValues ( bool  manage)
inlinevirtual

Indicates whether or not this instance should "manage" the values that are stored at each location in the collection as arrays.

"manage" should only be set true if the values stored in the collections are pointers to arrays of primitive types.

Defaults to "false".

If "manage" is set to true then:

  • When remove() is called, the array stored as the value at that location in the collection will be array-deleted.
  • When clear() is called, the array stored as the value at each location in the collection will be array-deleted.
  • When the = operator is called, the lvalue instance will attempt to create a copy of the array stored as the value in each location of the rvalue instance.
  • When the copy constructor is called, the new instance will attempt to create a copy of the array stored as the value in each location of the instance that is being copied.

If "manage" is set to false then:

  • When remove() is called, the array stored as the value at that location in the collection will not be array-deleted.
  • When clear() is called, the array stored as the value at each location in the collection will not be array-deleted.
  • When the = operator is called, the lvalue instance will not attempt to create a copy of the array stored as the value in each location of the rvalue instance, rather it will just copy the value or pointer.
  • When the copy constructor is called, the new instance will not attempt to create a copy of the array stored as the value in each location of the instance that is being copied, rather it will just copy the value or pointer.

To store managed arrays of non-primitive types as values, consider using a managed collection of managed staticarrays. For example:

    linkedlist< staticarray< myobject * > *>        l;
    l.setManageValues(true);

    staticarray< myobject * >       *s1=
                    new staticarray< myobject * >();
    s1.setManageValues(true);
    s1[0]=new myobject(...);
    s1[1]=new myobject(...);
    s1[2]=new myobject(...);
    l.append(s1);

    staticarray< myobject * >       *s2=
                    new staticarray< myobject * >();
    s2.setManageValues(true);
    s2[0]=new myobject(...);
    s2[1]=new myobject(...);
    s2[2]=new myobject(...);
    l.append(s2);

    ...

Note that setting this true implies setManageValues(false);

Reimplemented in table< valuetype >.

◆ setManageKeys()

void collection::setManageKeys ( bool  manage)
inlinevirtual

Indicates whether or not this instance should "manage" the keys that are stored at each location in the collection.

"manage" should only be set true if the keys stored in the collections are pointers to objects.

Defaults to "false".

If "manage" is set to true then:

  • When remove() is called, the object stored as the key at that location in the collection will be deleted.
  • When clear() is called, the object stored as the key at each location in the collection will be deleted.
  • When the = operator is called, the lvalue instance will attempt to create a copy of the object stored as the key in each location of the rvalue instance. Note that this can crash, fail, or even fail to compile if the objects being stored don't have properly implemented copy constructors.
  • When the copy constructor is called, the new instance will attempt to create a copy of the object stored as the key in each location of the instance that is being copied. Note that this can crash, fail, or even fail to compile if the objects being stored don't have properly implemented copy constructors.

If "manage" is set to false then:

  • When remove() is called, the object stored as the key at that location in the collection will not be deleted.
  • When clear() is called, the object stored as the key a each location in the collection will not be deleted.
  • When the = operator is called, the lvalue instance will not attempt to create a copy of the object stored as the key in each location of the rvalue instance, rather it will just copy the value or pointer.
  • When the copy constructor is called, the new instance will not attempt to create a copy of the object stored as the key in each location of the instance that is being copied, rather it will just copy the value or pointer.

Note that setting this true implies setManageArrayKeys(false);

◆ setManageValues()

void collection::setManageValues ( bool  manage)
inlinevirtual

Indicates whether or not this instance should "manage" the values that are stored at each location in the collection.

"manage" should only be set true if the values stored in the collections are pointers to objects.

Defaults to "false".

If "manage" is set to true then:

  • When remove() is called, the object stored as the value at that location in the collection will be deleted.
  • When clear() is called, the object stored as the value at each location in the collection will be deleted.
  • When the = operator is called, the lvalue instance will attempt to create a copy of the object stored as the value in each location of the rvalue instance. Note that this can crash, fail, or even fail to compile if the objects being stored don't have properly implemented copy constructors.
  • When the copy constructor is called, the new instance will attempt to create a copy of the object stored as the value in each location of the instance that is being copied. Note that this can crash, fail, or even fail to compile if the objects being stored don't have properly implemented copy constructors.

If "manage" is set to false then:

  • When remove() is called, the object stored as the value at that location in the collection will not be deleted.
  • When clear() is called, the object stored as the value a each location in the collection will not be deleted.
  • When the = operator is called, the lvalue instance will not attempt to create a copy of the object stored as the value in each location of the rvalue instance, rather it will just copy the value or pointer.
  • When the copy constructor is called, the new instance will not attempt to create a copy of the object stored as the value in each location of the instance that is being copied, rather it will just copy the value or pointer.

Note that setting this true implies setManageArrayValues(false);

Reimplemented in table< valuetype >.

◆ write() [1/2]

virtual ssize_t collection::write ( )
pure virtual

◆ write() [2/2]

virtual ssize_t collection::write ( output out)
pure virtual

◆ writeJson() [1/4]

virtual ssize_t collection::writeJson ( )
pure virtual

◆ writeJson() [2/4]

virtual ssize_t collection::writeJson ( bool  indent)
pure virtual

Writes a JSON representation of the collection to standard output.

If "indent" is true, then the output is automatically indented. If "indent" is false, then the tree is written without indentation.

Implemented in treecollection< valuetype >, tablecollection< valuetype >, scalarcollection< valuetype >, listcollection< valuetype >, dictionarycollection< keytype, valuetype >, and arraycollection< valuetype >.

◆ writeJson() [3/4]

virtual ssize_t collection::writeJson ( output out)
pure virtual

◆ writeJson() [4/4]

virtual ssize_t collection::writeJson ( output out,
bool  indent 
)
pure virtual

Writes a JSON representation of the collection to "out".

If "indent" is true, then the output is automatically indented. If "indent" is false, then the tree is written without indentation.

Implemented in treecollection< valuetype >, tablecollection< valuetype >, scalarcollection< valuetype >, listcollection< valuetype >, dictionarycollection< keytype, valuetype >, and arraycollection< valuetype >.