00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc. 00008 * 477 Richmond Street West, Suite 1001 00009 * Toronto, Ontario 00010 * Canada M5V 3E7 00011 * 416-504-9876 00012 */ 00013 00014 #ifndef __SIM_RootDataId_h__ 00015 #define __SIM_RootDataId_h__ 00016 00017 #include "SIM_API.h" 00018 #include <UT/UT_Hash.h> 00019 #include <UT/UT_String.h> 00020 00021 class SIM_API SIM_RootDataId : public UT_Hash 00022 { 00023 public: 00024 SIM_RootDataId() 00025 { myId = -1; } 00026 SIM_RootDataId(const SIM_RootDataId &src) 00027 : UT_Hash() 00028 { *this = src; } 00029 virtual ~SIM_RootDataId() 00030 { } 00031 00032 const UT_String &getName() const 00033 { return myName; } 00034 void setName(const char *name) 00035 { myName.harden(name); } 00036 00037 int getId() const 00038 { return myId; } 00039 void setId(int id) 00040 { myId = id; } 00041 00042 void clear() 00043 { myId = -1; myName = ""; } 00044 bool getIsClear() const 00045 { return (myId == -1 && !myName.isstring()); } 00046 00047 const SIM_RootDataId&operator=(const SIM_RootDataId &src) 00048 { 00049 myId = src.myId; 00050 myName.harden(src.myName); 00051 return *this; 00052 } 00053 int compare(const UT_Hash &a) const 00054 { 00055 // Compare ids first. 00056 if( myId != ((SIM_RootDataId &)a).myId ) 00057 return myId - ((SIM_RootDataId &)a).myId; 00058 00059 // Then compare strings (if non-empty). 00060 if( myName.isstring() && 00061 ((SIM_RootDataId &)a).myName.isstring() ) 00062 return strcmp(myName, 00063 ((SIM_RootDataId &)a).myName); 00064 00065 // Return 0 (equal) if both strings are empty. 00066 return (myName.isstring() || 00067 ((SIM_RootDataId &)a).myName.isstring()); 00068 } 00069 void copy(const UT_Hash &a) 00070 { 00071 *this = (SIM_RootDataId &)a; 00072 } 00073 unsigned hash() const 00074 { 00075 if( myName.isstring() ) 00076 return UT_String::hash(myName); 00077 return UTwang_inthash(myId); 00078 } 00079 UT_Hash *copy() const 00080 { 00081 return new SIM_RootDataId(*this); 00082 } 00083 00084 private: 00085 UT_String myName; 00086 int myId; 00087 }; 00088 00089 #endif 00090
1.5.9