GizmoBase

gzHashUtils.h

Go to the documentation of this file.
00001 //******************************************************************************
00002 // File         : gzHashUtils.h
00003 // Module       : gzBase
00004 // Description  : Utility file to handle hash comparing etc..
00005 // Author       : Anders Modén      
00006 // Product      : GizmoBase 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden
00009 //          
00010 // NOTE:    GizmoBase is a platform abstraction utility layer for C++. It contains 
00011 //          design patterns and C++ solutions for the advanced programmer.
00012 //
00013 //
00014 // Revision History...                          
00015 //                                  
00016 // Who  Date    Description                     
00017 //                                  
00018 // AMO  010315  Created file 
00019 //
00020 //******************************************************************************
00021 
00022 #ifndef __GZ_HASH_UTILS_H__
00023 #define __GZ_HASH_UTILS_H__
00024 
00030 #include "gzBasicTypes.h"
00031 
00032 // ******************** class definitions ***************************************
00033     
00034 //******************************************************************************
00035 // Class    : gzInstanceCompareInterface
00036 //                                  
00037 // Purpose  : Class to enable comparison of instances 
00038 //                                  
00039 // Notes    : - 
00040 //                                  
00041 // Revision History...                          
00042 //                                  
00043 // Who  Date    Description                     
00044 //                                  
00045 // AMO  981122  Created 
00046 //                                  
00047 //******************************************************************************
00048 
00055 class  GZ_BASE_EXPORT gzInstanceCompareInterface 
00056 {
00057 public:
00058 
00060     gzInstanceCompareInterface() { m_address=this; }
00061 
00063     gzInstanceCompareInterface(const gzVoid *address) { m_address=address; }
00064 
00066     gzULong hash() const                { return (gzULong)gzPtr2Val(m_address); }
00067 
00069     const gzVoid * getInstance() const  { return m_address; }
00070 
00072     gzBool operator ==(const gzInstanceCompareInterface &right)
00073     {
00074         return (m_address == right.m_address) ;
00075     }
00076 
00077 private:
00078     const gzVoid * m_address;
00079 
00080 };
00081 
00082 //******************************************************************************
00083 // Class    : gzValueCompareInterface
00084 //                                  
00085 // Purpose  : Template to enable comparison of generic values 
00086 //                                  
00087 // Notes    : - 
00088 //                                  
00089 // Revision History...                          
00090 //                                  
00091 // Who  Date    Description                     
00092 //                                  
00093 // AMO  990620  Created 
00094 //                                  
00095 //******************************************************************************
00101 class GZ_BASE_EXPORT gzValueCompareInterface 
00102 {
00103 public:
00104 
00105     gzValueCompareInterface(const gzDouble &value)              
00106     { 
00107         if(((gzLongLong)value)==value)
00108         {
00109             m_union.m_value=(gzLongLong)value;
00110             m_isDouble=FALSE;
00111         }
00112         else 
00113         {
00114             m_union.m_double=value; 
00115             m_isDouble=TRUE;
00116         }
00117     }
00118 
00119     gzULong             hash() const                { return (gzULong)(m_union.m_value & 0xffffffff) + (gzULong)((m_union.m_value>>32) & 0xffffffff); }
00120 
00121     gzDouble            getValue() const            { return m_isDouble?m_union.m_double:m_union.m_value;   }
00122 
00123     gzBool operator ==(const gzValueCompareInterface &right)
00124     {
00125         return (m_union.m_value == right.m_union.m_value) && (m_isDouble == right.m_isDouble);
00126     }
00127 
00128 
00129 private:
00130 
00131     union
00132     {
00133         gzLongLong  m_value;
00134         gzDouble    m_double;
00135     } m_union;
00136 
00137     gzBool          m_isDouble:1;
00138 };
00139 
00140 //******************************************************************************
00141 // Class    : gzULongCompareInterface
00142 //                                  
00143 // Purpose  : Template to enable comparison of long values 
00144 //                                  
00145 // Notes    : - 
00146 //                                  
00147 // Revision History...                          
00148 //                                  
00149 // Who  Date    Description                     
00150 //                                  
00151 // AMO  990620  Created 
00152 //                                  
00153 //******************************************************************************
00159 class GZ_BASE_EXPORT gzULongCompareInterface 
00160 {
00161 public:
00162 
00163     gzULongCompareInterface(const gzULong &value):m_value(value) {}
00164 
00165     gzULong             hash() const                { return m_value; }
00166 
00167     const gzULong &     getValue() const            { return m_value; }
00168 
00169     gzBool operator ==(const gzULongCompareInterface &right)
00170     {
00171         return (m_value == right.m_value) ;
00172     }
00173 
00174 
00175 private:
00176 
00177     gzULong m_value;
00178 };
00179 
00180 //******************************************************************************
00181 // Class    : gzULongLongCompareInterface
00182 //                                  
00183 // Purpose  : Template to enable comparison of ULongLong values 
00184 //                                  
00185 // Notes    : - 
00186 //                                  
00187 // Revision History...                          
00188 //                                  
00189 // Who  Date    Description                     
00190 //                                  
00191 // AMO  031217  Created 
00192 //                                  
00193 //******************************************************************************
00199 class GZ_BASE_EXPORT gzULongLongCompareInterface 
00200 {
00201 public:
00202 
00203     gzULongLongCompareInterface(const gzULongLong &value):m_value(value) {};
00204 
00205     gzULong         hash() const                { return (gzULong)(m_value & 0xffffffff) + (gzULong)((m_value>>32) & 0xffffffff); }
00206 
00207     const gzULongLong & getValue() const        { return m_value; }
00208 
00209     gzBool operator ==(const gzULongLongCompareInterface &right)
00210     {
00211         return (m_value == right.m_value) ;
00212     }
00213 
00214 
00215 private:
00216 
00217     gzULongLong m_value;
00218 };
00219 
00220 #endif // __GZ_HASH_UTILS_H__
00221 

Documentation for GizmoBase generated at Wed Feb 20 11:57:53 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond