Public Member Functions

imAttribTable Class Reference
[Utilities]

Attributes Table Class. More...

Public Member Functions

 imAttribTable (int hash_size)
 ~imAttribTable ()
int Count () const
void RemoveAll ()
void CopyFrom (const imAttribTable &table)
void MergeFrom (const imAttribTable &table)
void Set (const char *name, int data_type, int count, const void *data)
void SetInteger (const char *name, int data_type, int value)
void SetReal (const char *name, int data_type, double value)
void SetString (const char *name, const char *value)
void UnSet (const char *name)
const void * Get (const char *name, int *data_type=0, int *count=0) const
int GetInteger (const char *name, int index=0) const
double GetReal (const char *name, int index=0) const
const char * GetString (const char *name) const
void ForEach (void *user_data, imAttribTableCallback attrib_func) const

Detailed Description

All the attributes have a name, a type, a count and the data.
Names are usually strings with less that 30 chars.
Attributes are stored in a hash table for fast access.
We use the hash function described in "The Practice of Programming" of Kernighan & Pike.

Constructor & Destructor Documentation

imAttribTable::imAttribTable ( int  hash_size  )  [inline]

Creates an empty table. If size is zero the default size of 101 is used. Size must be a prime number. Other common values are 67, 599 and 1499.

imAttribTable::~imAttribTable (  )  [inline]

Destroys the table and all the attributes.


Member Function Documentation

int imAttribTable::Count (  )  const [inline]

Returns the number of elements in the table.

void imAttribTable::RemoveAll (  )  [inline]

Removes all the attributes in the table

void imAttribTable::CopyFrom ( const imAttribTable table  )  [inline]

Copies the contents of the given table into this table.

void imAttribTable::MergeFrom ( const imAttribTable table  )  [inline]

Merges the contents of the given table into this table.

void imAttribTable::Set ( const char *  name,
int  data_type,
int  count,
const void *  data 
) [inline]

Inserts an attribute into the table.
If data_type is BYTE then count can be -1 to indicate a NULL terminated string. Data is duplicated if not NULL, else data is initialized with zeros. See also imDataType.

void imAttribTable::SetInteger ( const char *  name,
int  data_type,
int  value 
) [inline]

Inserts a single integer attribute into the table.

void imAttribTable::SetReal ( const char *  name,
int  data_type,
double  value 
) [inline]

Inserts a single real attribute into the table.

void imAttribTable::SetString ( const char *  name,
const char *  value 
) [inline]

Inserts a string attribute into the table. data_type=IM_BYTE and is zero terminated.

void imAttribTable::UnSet ( const char *  name  )  [inline]

Removes an attribute from the table given its name.

const void* imAttribTable::Get ( const char *  name,
int *  data_type = 0,
int *  count = 0 
) const [inline]

Returns an attribute from the table. Returns the attribute if found, NULL otherwise. See also imDataType.

int imAttribTable::GetInteger ( const char *  name,
int  index = 0 
) const [inline]

Returns the attribute value at given index as an integer. If not found or complex returns 0.

double imAttribTable::GetReal ( const char *  name,
int  index = 0 
) const [inline]

Returns the attribute value at given index as a real. If not found or complex returns 0.

const char* imAttribTable::GetString ( const char *  name  )  const [inline]

Returns the attribute value as a string. If not found or not a zero terminated string returns 0.

void imAttribTable::ForEach ( void *  user_data,
imAttribTableCallback  attrib_func 
) const [inline]

For each attribute calls the user callback. If the callback returns 0 the function returns.