Shadowrun: Awakened 29 September 2011 - Build 871
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
DataStructures::Map< key_type, data_type, key_comparison_func > Class Template Reference

#include <DS_Map.h>

Inheritance diagram for DataStructures::Map< key_type, data_type, key_comparison_func >:

List of all members.

Classes

struct  MapNode

Public Member Functions

void Clear (void)
bool Delete (const key_type &key)
data_type & Get (const key_type &key) const
unsigned GetIndexAtKey (const key_type &key)
key_type GetKeyAtIndex (const unsigned int position) const
bool Has (const key_type &key) const
 Map ()
 Map (const Map &original_copy)
Mapoperator= (const Map &original_copy)
data_type & operator[] (const unsigned int position) const
data_type Pop (const key_type &key)
void RemoveAtIndex (const unsigned index)
void Set (const key_type &key, const data_type &data)
void SetExisting (const key_type &key, const data_type &data)
void SetNew (const key_type &key, const data_type &data)
unsigned Size (void) const
 ~Map ()

Static Public Member Functions

static void IMPLEMENT_DEFAULT_COMPARISON (void)
static int NodeComparisonFunc (const key_type &a, const MapNode &b)

Protected Member Functions

bool HasSavedSearchResult (const key_type &key) const
void SaveLastSearch (const key_type &key, unsigned index) const

Protected Attributes

unsigned lastSearchIndex
bool lastSearchIndexValid
key_type lastSearchKey
DataStructures::OrderedList
< key_type, MapNode,&Map::NodeComparisonFunc > 
mapNodeList

Detailed Description

template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func = defaultMapKeyComparison<key_type>>
class DataStructures::Map< key_type, data_type, key_comparison_func >

Note:
IMPORTANT! If you use defaultMapKeyComparison then call IMPLEMENT_DEFAULT_COMPARISON or you will get an unresolved external linker error.

Definition at line 35 of file DS_Map.h.


Constructor & Destructor Documentation

template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
DataStructures::Map< key_type, data_type, key_comparison_func >::Map ( )

Definition at line 93 of file DS_Map.h.

template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
DataStructures::Map< key_type, data_type, key_comparison_func >::~Map ( )

Definition at line 99 of file DS_Map.h.

    {
        Clear();
    }
template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
DataStructures::Map< key_type, data_type, key_comparison_func >::Map ( const Map< key_type, data_type, key_comparison_func > &  original_copy)

Member Function Documentation

template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
void DataStructures::Map< key_type, data_type, key_comparison_func >::Clear ( void  )

Definition at line 273 of file DS_Map.h.

References _FILE_AND_LINE_.

template<class key_type, class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
bool DataStructures::Map< key_type, data_type, key_comparison_func >::Delete ( const key_type &  key)

Definition at line 250 of file DS_Map.h.

Referenced by DataStructures::WeightedGraph< node_type, weight_type, allow_unlinkedNodes >::GenerateDisjktraMatrix().

    {
        if (HasSavedSearchResult(key))
        {
            lastSearchIndexValid=false;
            mapNodeList.RemoveAtIndex(lastSearchIndex);   
            return true;
        }

        bool objectExists;
        unsigned index;
        index=mapNodeList.GetIndexFromKey(key, &objectExists);
        if (objectExists)
        {
            lastSearchIndexValid=false;
            mapNodeList.RemoveAtIndex(index);
            return true;
        }
        else
            return false;
    }
template<class key_type, class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
data_type & DataStructures::Map< key_type, data_type, key_comparison_func >::Get ( const key_type &  key) const

Definition at line 124 of file DS_Map.h.

References RakAssert.

Referenced by DataStructures::WeightedGraph< node_type, weight_type, allow_unlinkedNodes >::GenerateDisjktraMatrix(), and DataStructures::WeightedGraph< node_type, weight_type, allow_unlinkedNodes >::GetSpanningTree().

    {
        if (HasSavedSearchResult(key))
            return mapNodeList[lastSearchIndex].mapNodeData;

        bool objectExists;
        unsigned index;
        index=mapNodeList.GetIndexFromKey(key, &objectExists);
        RakAssert(objectExists);
        SaveLastSearch(key,index);
        return mapNodeList[index].mapNodeData;
    }
template<class key_type, class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
unsigned DataStructures::Map< key_type, data_type, key_comparison_func >::GetIndexAtKey ( const key_type &  key)

Definition at line 138 of file DS_Map.h.

References RakAssert.

Referenced by DataStructures::WeightedGraph< node_type, weight_type, allow_unlinkedNodes >::GenerateDisjktraMatrix().

    {
        if (HasSavedSearchResult(key))
            return lastSearchIndex;

        bool objectExists;
        unsigned index;
        index=mapNodeList.GetIndexFromKey(key, &objectExists);
        if (objectExists==false)
        {
            RakAssert(objectExists);
        }
        SaveLastSearch(key,index);
        return index;
    }
template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
key_type DataStructures::Map< key_type, data_type, key_comparison_func >::GetKeyAtIndex ( const unsigned int  position) const
template<class key_type, class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
bool DataStructures::Map< key_type, data_type, key_comparison_func >::Has ( const key_type &  key) const

Definition at line 236 of file DS_Map.h.

Referenced by DataStructures::WeightedGraph< node_type, weight_type, allow_unlinkedNodes >::GetSpanningTree().

    {
        if (HasSavedSearchResult(key))
            return true;

        bool objectExists;
        unsigned index;
        index=mapNodeList.GetIndexFromKey(key, &objectExists);
        if (objectExists)
            SaveLastSearch(key,index);
        return objectExists;
    }
template<class key_type, class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
bool DataStructures::Map< key_type, data_type, key_comparison_func >::HasSavedSearchResult ( const key_type &  key) const [protected]

Definition at line 311 of file DS_Map.h.

    {
        (void) key;

        // Not threadsafe!
        return false;
        // return lastSearchIndexValid && key_comparison_func(key,lastSearchKey)==0;
    }
template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func = defaultMapKeyComparison<key_type>>
static void DataStructures::Map< key_type, data_type, key_comparison_func >::IMPLEMENT_DEFAULT_COMPARISON ( void  ) [inline, static]

Definition at line 38 of file DS_Map.h.

{DataStructures::defaultMapKeyComparison<key_type>(key_type(),key_type());}
template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func = defaultMapKeyComparison<key_type>>
static int DataStructures::Map< key_type, data_type, key_comparison_func >::NodeComparisonFunc ( const key_type &  a,
const MapNode b 
) [inline, static]

Definition at line 51 of file DS_Map.h.

        {
#ifdef _MSC_VER
#pragma warning( disable : 4127 ) // warning C4127: conditional expression is constant
#endif
            return key_comparison_func(a, b.mapNodeKey);
        }
template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
Map< key_type, data_type, key_comparison_func > & DataStructures::Map< key_type, data_type, key_comparison_func >::operator= ( const Map< key_type, data_type, key_comparison_func > &  original_copy)
template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
data_type & DataStructures::Map< key_type, data_type, key_comparison_func >::operator[] ( const unsigned int  position) const

Definition at line 280 of file DS_Map.h.

    {
        return mapNodeList[position].mapNodeData;
    }
template<class key_type, class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
data_type DataStructures::Map< key_type, data_type, key_comparison_func >::Pop ( const key_type &  key)

Definition at line 162 of file DS_Map.h.

References RakAssert.

    {
        bool objectExists;
        unsigned index;
        if (HasSavedSearchResult(key))
            index=lastSearchIndex;
        else
        {
            index=mapNodeList.GetIndexFromKey(key, &objectExists);
            RakAssert(objectExists);
        }       
        data_type tmp = mapNodeList[index].mapNodeData;
        mapNodeList.RemoveAtIndex(index);
        lastSearchIndexValid=false;
        return tmp;
    }
template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
void DataStructures::Map< key_type, data_type, key_comparison_func >::RemoveAtIndex ( const unsigned  index)

Definition at line 155 of file DS_Map.h.

template<class key_type, class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
void DataStructures::Map< key_type, data_type, key_comparison_func >::SaveLastSearch ( const key_type &  key,
unsigned  index 
) const [protected]

Definition at line 298 of file DS_Map.h.

    {
        (void) key;
        (void) index;

        /*
        lastSearchIndex=index;
        lastSearchKey=key;
        lastSearchIndexValid=true;
        */
    }
template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func>
void DataStructures::Map< key_type, data_type, key_comparison_func >::Set ( const key_type &  key,
const data_type &  data 
)

Definition at line 180 of file DS_Map.h.

References _FILE_AND_LINE_.

Referenced by DataStructures::WeightedGraph< node_type, weight_type, allow_unlinkedNodes >::GenerateDisjktraMatrix().

    {
        bool objectExists;
        unsigned index;

        if (HasSavedSearchResult(key))
        {
            mapNodeList[lastSearchIndex].mapNodeData=data;
            return;
        }
        
        index=mapNodeList.GetIndexFromKey(key, &objectExists);

        if (objectExists)
        {
            SaveLastSearch(key,index);
            mapNodeList[index].mapNodeData=data;
        }
        else
        {
            SaveLastSearch(key,mapNodeList.Insert(key,MapNode(key,data), true, _FILE_AND_LINE_));
        }
    }
template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func>
void DataStructures::Map< key_type, data_type, key_comparison_func >::SetExisting ( const key_type &  key,
const data_type &  data 
)

Definition at line 205 of file DS_Map.h.

References RakAssert.

    {
        bool objectExists;
        unsigned index;

        if (HasSavedSearchResult(key))
        {
            index=lastSearchIndex;
        }
        else
        {
            index=mapNodeList.GetIndexFromKey(key, &objectExists);
            RakAssert(objectExists);
            SaveLastSearch(key,index);
        }       

        mapNodeList[index].mapNodeData=data;
    }   
template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func>
void DataStructures::Map< key_type, data_type, key_comparison_func >::SetNew ( const key_type &  key,
const data_type &  data 
)

Definition at line 225 of file DS_Map.h.

References _FILE_AND_LINE_, and RakAssert.

    {
#ifdef _DEBUG
        bool objectExists;
        mapNodeList.GetIndexFromKey(key, &objectExists);
        RakAssert(objectExists==false);
#endif
        SaveLastSearch(key,mapNodeList.Insert(key,MapNode(key,data), true, _FILE_AND_LINE_));
    }
template<class key_type , class data_type , int(*)(const key_type &, const key_type &) key_comparison_func>
unsigned DataStructures::Map< key_type, data_type, key_comparison_func >::Size ( void  ) const

Member Data Documentation

template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func = defaultMapKeyComparison<key_type>>
unsigned DataStructures::Map< key_type, data_type, key_comparison_func >::lastSearchIndex [protected]
template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func = defaultMapKeyComparison<key_type>>
bool DataStructures::Map< key_type, data_type, key_comparison_func >::lastSearchIndexValid [protected]
template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func = defaultMapKeyComparison<key_type>>
key_type DataStructures::Map< key_type, data_type, key_comparison_func >::lastSearchKey [protected]
template<class key_type, class data_type, int(*)(const key_type &, const key_type &) key_comparison_func = defaultMapKeyComparison<key_type>>
DataStructures::OrderedList< key_type,MapNode,&Map::NodeComparisonFunc > DataStructures::Map< key_type, data_type, key_comparison_func >::mapNodeList [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