Shadowrun: Awakened 29 September 2011 - Build 871
Public Member Functions | Protected Attributes
ManagedDictionary< Key, Value > Class Template Reference

#include <ManagedDictionary.h>

Inheritance diagram for ManagedDictionary< Key, Value >:

List of all members.

Public Member Functions

__inline bool getManaged () const
 ManagedDictionary ()
 ManagedDictionary (bool manageMemory)
 ManagedDictionary (bool manageMemory, Value *defaultValue)
__inline void setManaged (bool val)
 ~ManagedDictionary ()

Protected Attributes

bool _manageMemory

Detailed Description

template<class Key, class Value>
class ManagedDictionary< Key, Value >

An extension of the Dictionary class This will optionally 'manage' memory by deleting all values still contained when the object is destroyed NOTE: By default, memory management is NOT enabled The value for this dictionary is always held as a pointer, get/set type operations treat the Value as a pointer EG ManagedDictionary<int, Command> will use int as the key and Command* as the value NOTE: When calling getSafe(Key), NULL is returned if no match for the key is found

Definition at line 17 of file ManagedDictionary.h.


Constructor & Destructor Documentation

template<class Key, class Value>
ManagedDictionary< Key, Value >::ManagedDictionary ( ) [inline]

Constructor

Definition at line 26 of file ManagedDictionary.h.

                        : _manageMemory(false) 
    {
        setDefaultValue(NULL);
    }
template<class Key, class Value>
ManagedDictionary< Key, Value >::ManagedDictionary ( bool  manageMemory) [inline]

Constructor Sets whether or not memory is managed by this dictionary

Definition at line 35 of file ManagedDictionary.h.

                                         : _manageMemory(manageMemory) 
    {
        setDefaultValue(NULL);
    }
template<class Key, class Value>
ManagedDictionary< Key, Value >::ManagedDictionary ( bool  manageMemory,
Value defaultValue 
) [inline]

Constructor Sets whether or not memory is managed and the default value returned by this dictionary

Definition at line 44 of file ManagedDictionary.h.

                                                              : _manageMemory(manageMemory) 
    {
        setDefaultValue(defaultValue);
    }
template<class Key, class Value>
ManagedDictionary< Key, Value >::~ManagedDictionary ( ) [inline]

Destructor If "managed" is true, then this will delete all values in this dictionary

Definition at line 53 of file ManagedDictionary.h.

    {
        //if we are not managing memory, then abort
        if(!_manageMemory)
            return;

        //if we are managing memory, then delete all objects in the map
        std::map<Key, Value*>::const_iterator iter = begin();
        while(iter != end())
        {
            delete (iter->second);
            ++iter;
        }
    }

Member Function Documentation

template<class Key, class Value>
__inline bool ManagedDictionary< Key, Value >::getManaged ( ) const [inline]

Definition at line 69 of file ManagedDictionary.h.

template<class Key, class Value>
__inline void ManagedDictionary< Key, Value >::setManaged ( bool  val) [inline]

Definition at line 70 of file ManagedDictionary.h.


Member Data Documentation

template<class Key, class Value>
bool ManagedDictionary< Key, Value >::_manageMemory [protected]

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

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net