libidx
ebl::srg< T > Class Template Reference

#include <srg.h>

Inheritance diagram for ebl::srg< T >:
ebl::smart_pointer

List of all members.

Public Member Functions

 srg ()
 builds an empty srg (no data is allocated)
 srg (intg s)
 allocate an srg of size s
 ~srg ()
intg size ()
 return the size (number of items)
intg changesize (intg s)
intg growsize (intg s)
 increase size of data chunk
intg growsize_chunk (intg s, intg s_chunk)
 increase size of data chunk by a given step s_chunk
get (intg i)
 access method: return the i-th item.
T * get_data ()
 Returns a pointer to the beginning of the data segment.
void set_data (T *ptr)
 Sets a pointer to the beginning of the data segment.
void set (intg i, T val)
 sets i-th element to val.
void clear ()
 fill data with zeros.
void pretty (FILE *f)
 prints innards

Friends

class idx
class idxiter
class noncontiguous_idxiter
class contiguous_idxiter
class idxlooper

Detailed Description

template<typename T>
class ebl::srg< T >

srg is a container for arrays of data. It contains a pointer to a dynamically allocated chunk of data, a size, and a reference counter. Access structures such as idx, point to an srg that contains the data. Several idx's can share an srg allowing access to the data in multiple ways. Whenever an idx is created that that points an srg, the reference counter of that srg is incremented through the lock() member function. When the reference counter is reaches 0, the srg is deallocated. An srg must always be created with new, and never created as an automatic variable. For that reason, the destructor is private. So, if compiling your code produces an error like "srg<T>::~srg() is private", you mistakenly allocated an srg as an automatic variable instead of new.


Constructor & Destructor Documentation

template<typename T >
ebl::srg< T >::~srg ( )

destructor: deallocates the data. This is automatically called when the reference counter reaches 0. The destructor is made private so that the compiler will complain if someone decide to create an srg on the stack (as an automatic variable). An srg must ALWAYS be created with new.


Member Function Documentation

template<typename T >
intg ebl::srg< T >::changesize ( intg  s)

change size to s. This must be used with extreme caution, because reducing the size of an srg ma cause some idx that point to it to access non-existent data.


The documentation for this class was generated from the following files: