- Timestamp:
- Oct 24, 2006, 7:36:57 AM (18 years ago)
- Location:
- trunk/src/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpBindingsDict.cc
r135 r536 67 67 68 68 69 RpLibrary* retVal = NULL; 70 71 retVal = *(ObjDict_Lib.find(objKey).getValue()); 72 73 if (retVal == *(ObjDict_Lib.getNullEntry().getValue())) { 74 retVal = NULL; 75 } 76 77 return retVal; 69 RpDictEntry DICT_TEMPLATE_L* libEntry = &(ObjDict_Lib.getNullEntry()); 70 RpDictEntry DICT_TEMPLATE_L* nullEntry = &(ObjDict_Lib.getNullEntry()); 71 72 libEntry = &(ObjDict_Lib.find(objKey)); 73 74 75 if ( (!libEntry->isValid()) || (libEntry == nullEntry) ) { 76 return NULL; 77 } 78 79 return *(libEntry->getValue()); 78 80 79 81 } … … 158 160 getObject_UnitsStr(int objKey) { 159 161 162 /* 160 163 std::string basisName = *(ObjDictUnits.find(objKey).getValue()); 161 164 … … 165 168 } 166 169 167 return RpUnits::find(basisName); 170 return RpUnits::find(basisName); 171 */ 172 173 RpDictEntry DICT_TEMPLATE_U* unitEntry = &(ObjDictUnits.getNullEntry()); 174 RpDictEntry DICT_TEMPLATE_U* nullEntry = &(ObjDictUnits.getNullEntry()); 175 176 unitEntry = &(ObjDictUnits.find(objKey)); 177 178 179 if ( (!unitEntry->isValid()) || (unitEntry == nullEntry) ) { 180 return NULL; 181 } 182 183 return RpUnits::find(*(unitEntry->getValue())); 168 184 169 185 } -
trunk/src/core/RpDict.h
r511 r536 98 98 // const void* setValue(const void* value); 99 99 const ValType* setValue(const ValType& value); 100 bool isValid() const; 100 101 101 102 // erases this entry from its table … … 108 109 friend class RpDictIterator<KeyType,ValType>; 109 110 110 // no_arg constructor111 // use the key and clientData's default [no-arg] constructor112 RpDictEntry()113 : nextPtr (NULL),114 tablePtr (NULL),115 hash (0) // ,116 // clientData (),117 // key ()118 {119 }120 121 111 // one-arg constructor 122 112 // maybe get rid of this one? 113 // use the clientData's default [no-arg] constructor 114 /* 123 115 RpDictEntry(KeyType newKey) 124 : nextPtr (NULL), 125 tablePtr (NULL), 126 hash (0), 127 clientData (NULL),116 : nextPtr (NULL), 117 tablePtr (NULL), 118 hash (0), 119 // clientData (NULL), 128 120 key (newKey) 129 121 { 130 122 } 123 */ 131 124 132 125 // two-arg constructor 133 126 RpDictEntry(KeyType newKey, ValType newVal) 134 : nextPtr (NULL), 135 tablePtr (NULL), 136 hash (0), 127 : nextPtr (NULL), 128 tablePtr (NULL), 129 hash (0), 137 130 clientData (newVal), 138 key (newKey) 131 key (newKey), 132 valid (&clientData) 139 133 { 140 134 } … … 142 136 /* 143 137 RpDictEntry(KeyType* newKey, ValType* newVal) 144 : nextPtr (NULL), 145 tablePtr (NULL), 146 hash (0), 138 : nextPtr (NULL), 139 tablePtr (NULL), 140 hash (0), 147 141 clientData (*newVal), 148 142 key (*newKey) … … 151 145 152 146 RpDictEntry(KeyType newKey, RpDict* table) 153 : nextPtr (NULL), 154 tablePtr (table), 155 hash (0), 147 : nextPtr (NULL), 148 tablePtr (table), 149 hash (0), 156 150 // clientData (NULL), 157 151 key (newKey) … … 165 159 tablePtr = entry.tablePtr; 166 160 hash = entry.hash; 167 clientData = (ValType) entry.getValue(); 168 key = (KeyType) entry.getKey(); 161 162 if (entry.valid != NULL) { 163 clientData = (ValType) entry.getValue(); 164 key = (KeyType) entry.getKey(); 165 valid = &clientData; 166 } 167 else { 168 valid = NULL; 169 } 170 169 171 } 170 172 … … 177 179 * chain. */ 178 180 179 RpDict<KeyType,ValType> 180 *tablePtr; /* Pointer to table containing entry. */181 RpDict<KeyType,ValType>* 182 tablePtr; /* Pointer to table containing entry. */ 181 183 182 184 unsigned int hash; /* Hash value. */ 183 185 184 186 ValType clientData; /* Application stores something here 185 187 * with Tcl_SetHashValue. */ 186 188 187 189 KeyType key; /* entry key */ 188 190 189 190 191 ValType* valid; /* is this a valid object */ 192 193 194 // no_arg constructor 195 // 196 RpDictEntry() 197 : nextPtr (NULL), 198 tablePtr (NULL), 199 hash (0), 200 valid (NULL) 201 // clientData (), 202 // key () 203 { 204 } 191 205 192 206 }; … … 207 221 // returns !0 on failure (object cannot be inserted or dne) 208 222 // 209 /*virtual*/ RpDict<KeyType,ValType>& 210 set( KeyType& key, 211 ValType& value, 212 int *newPtr=NULL ); 223 /*virtual*/ RpDict<KeyType,ValType>& 224 set( KeyType& key, 225 ValType& value, 226 int *newPtr=NULL ); 213 227 214 228 // find an RpUnits object that should exist in RpUnitsTable … … 217 231 find( KeyType& key ); 218 232 219 /*virtual*/ RpDictEntry<KeyType,ValType>& operator[]( KeyType& key) 220 { 221 return find(key); 233 /*virtual*/ RpDictEntry<KeyType,ValType>& operator[]( KeyType& key) 234 { 235 return find(key); 222 236 } 223 237 … … 236 250 237 251 // default constructor 238 RpDict () 252 RpDict () 239 253 : SMALL_RP_DICT_SIZE(4), 240 254 REBUILD_MULTIPLIER(3), … … 245 259 downShift(28), 246 260 mask(3) 247 { 261 { 248 262 249 263 staticBuckets[0] = staticBuckets[1] = 0; … … 253 267 nullEntry = new RpDictEntry<KeyType,ValType>(); 254 268 269 assert(nullEntry != NULL); 270 255 271 // std::cout << "inside RpDict Constructor" << std::endl; 256 272 … … 264 280 265 281 // destructor 266 /*virtual*/ ~RpDict() 282 /*virtual*/ ~RpDict() 267 283 { 268 284 // probably need to delete all the entries as well … … 366 382 int* newPtr) 367 383 { 368 RpDictEntry<KeyType,ValType> *hPtr ;369 unsigned int hash ;370 int index ;384 RpDictEntry<KeyType,ValType> *hPtr = NULL; 385 unsigned int hash = 0; 386 int index = 0; 371 387 372 388 assert(&key); … … 461 477 462 478 template <typename KeyType, typename ValType> 463 RpDictEntry<KeyType,ValType>& 479 RpDictEntry<KeyType,ValType>& 464 480 RpDict<KeyType,ValType>::find(KeyType& key) 465 481 { 466 RpDictEntry<KeyType,ValType> *hPtr ;467 unsigned int hash ;468 int index ;482 RpDictEntry<KeyType,ValType> *hPtr = NULL; 483 unsigned int hash = 0; 484 int index = 0; 469 485 470 486 assert(&key); … … 513 529 * Side Effects: 514 530 * moves iterator to the beginning of the hash table. 515 * 531 * 516 532 * 517 533 *************************************************************************/ … … 567 583 RpDictIterator<KeyType,ValType>::next() 568 584 { 569 RpDictEntry<KeyType,ValType>* hPtr ;585 RpDictEntry<KeyType,ValType>* hPtr = NULL; 570 586 571 587 while (srchNextEntryPtr == NULL) { … … 599 615 RpDict<KeyType,ValType>::clear() 600 616 { 601 RpDictEntry<KeyType,ValType> *hPtr ;617 RpDictEntry<KeyType,ValType> *hPtr = NULL; 602 618 RpDictIterator<KeyType,ValType> iter((RpDict&)*this); 603 619 … … 614 630 /************************************************************************** 615 631 * 616 * RpDict & getNullEntry()632 * RpDictEntry & getNullEntry() 617 633 * get the nullEntry hash entry for initialization of references 618 634 * … … 657 673 RpDictEntry<KeyType,ValType>::erase() 658 674 { 659 RpDictEntry<KeyType,ValType> *prevPtr ;660 RpDictEntry<KeyType,ValType> **bucketPtr ;675 RpDictEntry<KeyType,ValType> *prevPtr = NULL; 676 RpDictEntry<KeyType,ValType> **bucketPtr = NULL; 661 677 int index = 0; 662 678 … … 704 720 // clientData = NULL; 705 721 // key = NULL; 722 valid = NULL; 706 723 707 724 // delete the object. … … 740 757 * 741 758 * retrieve the value of the current object 759 * it is the caller responsibility to check isValid() to see if the 760 * object actually holds a valid value. 742 761 * 743 762 * Results: … … 778 797 { 779 798 clientData = value; 799 valid = &clientData; 780 800 return (const ValType*) &clientData; 781 801 } … … 793 813 } 794 814 815 /* 816 *---------------------------------------------------------------------- 817 * 818 * bool RpDictEntry::isValid() 819 * 820 * is this a valid object, return true or false 821 * 822 * Results: 823 * tells the user if the object is valid true or false 824 * 825 * Side effects: 826 * None. 827 * 828 *---------------------------------------------------------------------- 829 */ 830 831 template <typename KeyType, typename ValType> 832 bool 833 RpDictEntry<KeyType,ValType>::isValid() const 834 { 835 if (valid) { 836 return true; 837 } 838 return false; 839 } 840 795 841 796 842 /*************************************************************************/ … … 824 870 { 825 871 int oldSize=0, count=0, index=0; 826 RpDictEntry<KeyType,ValType> **oldBuckets ;827 RpDictEntry<KeyType,ValType> **oldChainPtr , **newChainPtr;828 RpDictEntry<KeyType,ValType> *hPtr ;829 830 void *key;872 RpDictEntry<KeyType,ValType> **oldBuckets = NULL; 873 RpDictEntry<KeyType,ValType> **oldChainPtr = NULL, **newChainPtr = NULL; 874 RpDictEntry<KeyType,ValType> *hPtr = NULL; 875 876 // void *key = NULL; 831 877 832 878 oldSize = numBuckets; … … 863 909 *oldChainPtr = hPtr->nextPtr; 864 910 865 key = (void *) hPtr->getKey();911 // key = (void *) hPtr->getKey(); 866 912 867 913 index = randomIndex(hPtr->hash); … … 905 951 const char *stopAddr = (const char *) keyPtr + sizeof(&keyPtr) - 1 ; 906 952 const char *str = (const char *) keyPtr; 907 unsigned int result ;953 unsigned int result = 0; 908 954 int c; 909 955 … … 942 988 { 943 989 const char *str = (const char *) (keyPtr->c_str()); 944 unsigned int result ;945 int c ;990 unsigned int result = 0; 991 int c = 0; 946 992 947 993 result = 0; … … 964 1010 { 965 1011 const char *str = (const char *) (keyPtr); 966 unsigned int result ;967 int c ;1012 unsigned int result = 0; 1013 int c = 0; 968 1014 969 1015 result = 0; -
trunk/src/core/RpUnits.cc
r534 r536 680 680 681 681 // dict pointer 682 /* 682 683 const RpUnits* unitEntry = NULL; 684 const RpUnits* nullEntry = NULL; 685 */ 686 RpDictEntry<std::string,RpUnits*>* unitEntry = &(dict->getNullEntry()); 687 RpDictEntry<std::string,RpUnits*>* nullEntry = &(dict->getNullEntry()); 683 688 double exponent = 1; 684 689 int idx = 0; … … 693 698 } 694 699 700 /* 695 701 unitEntry = *(dict->find(key).getValue()); 702 nullEntry = *(dict->getNullEntry().getValue()); 703 */ 704 705 unitEntry = &(dict->find(key)); 696 706 697 707 // dict pointer 698 if (unitEntry == *(dict->getNullEntry().getValue()) ) { 699 unitEntry = NULL; 700 } 701 702 return unitEntry; 708 if ( (!unitEntry->isValid()) || (unitEntry == nullEntry) ) { 709 // unitEntry = NULL; 710 return NULL; 711 } 712 713 return *(unitEntry->getValue()); 703 714 } 704 715 -
trunk/src/core/RpUnits.h
r534 r536 649 649 static const RpUnits* grabUnits (std::string inStr, int* offset); 650 650 static int negateListExponents(RpUnitsList& unitsList); 651 static int RpUnits::printList(RpUnitsList& unitsList);652 653 static int RpUnits::compareListEntryBasis( RpUnitsList& fromList,654 655 656 657 static int RpUnits::compareListEntrySearch( RpUnitsList& fromList,658 659 660 661 void RpUnits::connectConversion(conversion* conv) const;662 void RpUnits::connectIncarnation(const RpUnits* unit) const;651 static int printList(RpUnitsList& unitsList); 652 653 static int compareListEntryBasis( RpUnitsList& fromList, 654 RpUnitsListIter& fromIter, 655 RpUnitsListIter& toIter); 656 657 static int compareListEntrySearch( RpUnitsList& fromList, 658 RpUnitsListIter& fromIter, 659 RpUnitsListIter& toIter); 660 661 void connectConversion(conversion* conv) const; 662 void connectIncarnation(const RpUnits* unit) const; 663 663 664 664 // return the conversion object that will convert
Note: See TracChangeset
for help on using the changeset viewer.