OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: File dialog code CEGUIHashMapTemplates.h for Linux
View page
Source of version: 3
(current)
__CEGUIHashMapTemplates.h__ {CODE(wrap="1", colors="c++")}/***************************************************************************** Written by spookyboo ported to Linux by ancestral (granturkoATgmail.com) *****************************************************************************/ #ifndef _CEGUI_HASHMAP_TEMPLATES_H_ #define _CEGUI_HASHMAP_TEMPLATES_H_ #include <ext/hash_map> #include "OgreString.h" #if defined(_MSC_VER) # pragma warning(push) # pragma warning(disable : 4786) #endif using namespace std; // this is needed becouse hash function for string objects is not defined // template specialization for strings (already defined in OgreString.h ) /* namespace __gnu_cxx { template <> struct hash<std::string> { size_t operator() (const std::string& x) const { return hash<const char*>()(x.c_str()); // hash<const char*> already exists } }; } */ namespace CEGUI { /********************************************************************************************* Method : getEntryFromHashMap Description : The following template methods provide generic methods, such as adding, searching and deleting entries to/from a HashMap. The HashMap is a hash_map with attributes of type Z as an identifying key and attributes of class T as the object to be stored. This template method is used to search an object in the HashMap, using the id as search key. Parameters : NA Returnvalue : NA **********************************************************************************************/ template<typename Z, class T> T getEntryFromHashMap (Z id, __gnu_cxx::hash_map<Z, T>* hashMap) { // Search the entry in the hashMap if (hashMap) { typename __gnu_cxx::hash_map<Z, T>::iterator hashMapIterator; hashMapIterator = hashMap->find (id); if (hashMapIterator != hashMap->end()) { // Found it return hashMapIterator->second; } } return NULL; }; /********************************************************************************************* Method : addEntryToHashMap Description : This template method is used to add an entry to the hashMap. If an entry with the same key is already present, the stored object is deleted! Parameters : NA Returnvalue : NA **********************************************************************************************/ template<typename Z, class T> void addEntryToHashMap (Z id, T object, __gnu_cxx::hash_map<Z, T>* hashMap) { if (hashMap) { T existingObject = getEntryFromHashMap (id, hashMap); if (existingObject == NULL) { // Not found; insert it hashMap->insert (make_pair(id, object)); } else { if (object != existingObject) { // The key exists, but the object differs hashMap->erase (id); // Remove the entry from the hash_map delete existingObject; // Delete the object hashMap->insert (make_pair(id, object)); } } } }; /********************************************************************************************* Method : eraseEntryFromHashMap Description : This template method is used to remove one entry from the hashMap. The entry itself will not be deleted! Parameters : NA Returnvalue : NA **********************************************************************************************/ template<typename Z, class T> void eraseEntryFromHashMap (Z id, __gnu_cxx::hash_map<Z, T>* hashMap) { // Remove one entry; it wil not be deleted if (hashMap) { typename __gnu_cxx::hash_map<Z, T>::iterator hashMapIterator; hashMapIterator = hashMap->find (id); if (hashMapIterator != hashMap->end()) { // Found it hashMap->erase (hashMapIterator); } } }; /********************************************************************************************* Method : deleteEntryFromHashMap Description : This template method is used to remove one entry from the hashMap and delete it. Parameters : NA Returnvalue : NA **********************************************************************************************/ template<typename Z, class T> void deleteEntryFromHashMap (Z id, __gnu_cxx::hash_map<Z, T>* hashMap) { // Remove one entry; it wil not be deleted if (hashMap) { typename __gnu_cxx::hash_map<Z, T>::iterator hashMapIterator; hashMapIterator = hashMap->find (id); if (hashMapIterator != hashMap->end()) { // Found it hashMap->erase (hashMapIterator); delete hashMapIterator->second; } } }; /********************************************************************************************* Method : deleteAllEntriesFromHashMap Description : This template method is used to delete all entries from the hashMap. Parameters : NA Returnvalue : NA **********************************************************************************************/ template<typename Z, class T> void deleteAllEntriesFromHashMap (__gnu_cxx::hash_map<Z, T>* hashMap) { // Delete all hashMap entries if (hashMap) { typename __gnu_cxx::hash_map<Z, T>::iterator hashMapIterator; for (hashMapIterator = hashMap->begin(); hashMapIterator != hashMap->end(); hashMapIterator++) { if (hashMapIterator->second) delete hashMapIterator->second; } hashMap->clear(); } }; }; #endif {CODE}
Search by Tags
Search Wiki by Freetags
Latest Changes
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
Critter AI
Mogre Add-ons
MOGRE
Mogre MyGUI wrapper
MOGRE Editable Terrain Manager
...more
Search
Find
Advanced
Search Help
Online Users
46 online users