Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "Object.h"
- #include "QuickMap.h"
- typedef const char string_id[17];
- typedef unsigned long bin_id;
- template <class T>
- class StringMap :
- public Object {
- public:
- StringMap(T* PO );
- virtual ~StringMap( );
- void put( string_id str_id, T* pT );
- T* get( string_id ) const;
- static bin_id calculateCheckSum( string_id );
- private:
- QuickMap<bin_id, T*>* m_POMap;
- T* m_POEmpty = NULL;
- };
- template<class T>
- inline StringMap<T>::StringMap(T* PO )
- {
- m_POEmpty = PO;
- m_POMap = new QuickMap<bin_id, T*>();
- }
- template<class T>
- inline StringMap<T>::~StringMap( )
- {
- delete m_POMap;
- }
- template<class T>
- inline void StringMap<T>::put( string_id str_id, T * pT )
- {
- m_POMap->put( calculateCheckSum( str_id ), pT );
- }
- template<class T>
- inline T * StringMap<T>::get( string_id str_id) const
- {
- bin_id id = calculateCheckSum( str_id );
- if ( m_POMap->contains( id ) )
- return m_POMap->get( id );
- return m_POEmpty;
- }
- template<class T>
- inline bin_id StringMap<T>::calculateCheckSum( string_id id)
- {
- dword len = strlen( id );
- bin_id result = 0;
- byte b = 0;
- for ( dword i = 0; i < len; i++ ) {
- b = ( byte ) toupper( id[ i ] );
- if ( isalnum( b ) )
- result += (b * i * len) + b + len;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement