mxmPerlStyleHash Class Reference
[modularMX Runtime Platform Core]

Perl-style Hash storing key/value string pairs, especially useful for processing configuration files. More...

#include <mxmPerlStyleHash.h>

Inheritance diagram for mxmPerlStyleHash:

mxmList mxmContainer mxmObject mxmContainerInterface mxmInterface mx::Framework::ComponentDescriptor List of all members.

Public Member Functions

 mxmPerlStyleHash (const mxmPerlStyleHash &other_hash)
mxmPerlStyleHashoperator= (const mxmPerlStyleHash &other_hash)
mxmStringoperator[] (const mxmString &key)
 Returns a reference to the value for a given key.
mxmString value (const mxmString &key) const
 Also returns the value for a given key, but does not implicitly create the key if it is not present.
void deleteKey (const mxmString &key)
 If present, the key/value pair addressed by the given key is purged from the hash.
void setCaseInsensitiveKeysMode (bool enabled)
 Specify whether or not you want your keys to be treated case sensitively.
void mergeKeys (const mxmPerlStyleHash &other_hash, const mxmStringList &allowed_key_mask, bool treat_mask_as_prefixes=false, const mxmString &target_key_prefix="")
 Merges in keys from the other hash, but only those that are cleared by the allowed_key_mask.
void mergeKeysFromString (const mxmString &hash_string, const mxmString &pair_delimiters, const mxmString &key_value_separators, const mxmString &trim_chars)
 Merges in key/value pairs contained in the specified string.
mxm::smart< mxmStringListenumerateKeys (void) const
 Generates a list of all keys.
void purgeValueCharacters (const mxmString &key, const mxmString &characters_to_purge)
 Removes all occurances of the characters specified from the value for the given key.
mxmString concatenate (const mxmString &pair_separator=",", const mxmString &key_value_separator="=") const
 Converts the whole hash into a single string.
int size (void) const
 (Re)implementation, to make sense with hashes.
mxmPerlStyleHash::Iterator iterator (void) const
 Provides the calling context with an external iterator.
void appendItemToTail (mxmObject *item)
 (Re)implementation, to make sense with hashes.

Static Public Member Functions

static mxmPerlStyleHash emptyHash (void)
 Returns an empty hash.
static mxmPerlStyleHash fromCommandLineArg (const mxmString &arg)
 Produces a hash from an appropriate command line argument.

Private Member Functions

void init_mxmPerlStyleHash (void)

Private Attributes

bool CaseInsensitiveKeys
void * StableABIDataExtension

Classes

class  Iterator
 Iterator implementation for mxmPerlStyleHash es. More...
class  KeyValuePair
 Represents one key/value string pair in a hash. More...
class  KeyValuePairDecider
 Installed with the mxmList, so only key/value pairs can be added. More...

Detailed Description

Perl-style Hash storing key/value string pairs, especially useful for processing configuration files.

Since it is still an option to replace many of the camera software's Perl scripts by small and efficient C++ applications, we tried to mimic with this class the convenient handling Perl offers for this kind of data type.

Note that we are perfectly aware of the true meaning of the term hash. However, within the context of this class we use it in the way Perl does.

Note also that in contrast to Perl hashes, for mxmHash es, the sequential ordering of the stored key/value pairs is significant - when iterating over a hash's key/value pairs, they are reproduced in the same order in which they were originally added to the hash.

Check out some stuff you can do to hashes:

  mxmPerlStyleHash hash;
  mxmPerlStyleHash::KeyValuePair *key_value_pair;

  hash["kai"] = "funz";                           // add key/value pair
  hash["daniel"] = "kabs";
  hash["david"] = "gruys";
  hash["kai"] = "hergenroether";                  // overwrite value
  printf("kai is %s\n", hash["kai"].text());      // access a key's value
  if(hash["steve"].isNull())                      // check whether a key is
    printf("steve does not exist!\n");            //   present
  hash.deleteKey("kai");                          // purges a key
  printf("# hash entries : %d\n", hash.size());   // get number of keys

  mxmPerlStyleHash::Iterator iter                 // read out all key/value
                              = hash.iterator();  //   pairs
  while(key_value_pair
         = static_cast<mxmPerlStyleHash::KeyValuePair *>(iter.nextItem())) {
    printf("-->%s = %s\n", key_value_pair->key()->text(),
                           key_value_pair->value()->text());
  }

Author:
[khe] Kai Hergenroether


Member Function Documentation

void mxmPerlStyleHash::appendItemToTail mxmObject item  )  [virtual]
 

(Re)implementation, to make sense with hashes.

A previous occurance of the respective key is wasted. The new key/value pair is appended to the tail of the list.

Not recommended not be used, however. Obsoleted by the [] operator anyways

Attention:
In violation of what was said for mxmList::appendItemToTail(), the previous key occurance, if present, might be lost. Don't use.

Reimplemented from mxmList.

mxmString & mxmPerlStyleHash::operator[] const mxmString key  ) 
 

Returns a reference to the value for a given key.

In fact, this is the main hash class functionality. Use this operator to both set and retrieve key values. Setting key values happens by assigning to the string returned by the operator. If the string returned is a null-string, as can be tested via mxmString::isNull(), the key is not in the hash.

void mxmPerlStyleHash::setCaseInsensitiveKeysMode bool  enabled  ) 
 

Specify whether or not you want your keys to be treated case sensitively.

The default is case sensitive keys.

Note:
This method will clear the hash.

int mxmPerlStyleHash::size void   )  const [virtual]
 

(Re)implementation, to make sense with hashes.

This reimplementation is slow.

Reimplemented from mxmList.

mxmString mxmPerlStyleHash::value const mxmString key  )  const
 

Also returns the value for a given key, but does not implicitly create the key if it is not present.

For non-existent keys the method returns a null-string.


The documentation for this class was generated from the following files:
Generated on Fri Jun 29 17:21:05 2007 for MxPEG SDK by  doxygen 1.4.6