00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_UTIL_STLMAP_H_
00019 #define _DECAF_UTIL_STLMAP_H_
00020
00021 #include <map>
00022 #include <memory>
00023 #include <decaf/lang/Pointer.h>
00024 #include <decaf/lang/exceptions/UnsupportedOperationException.h>
00025 #include <decaf/util/ConcurrentModificationException.h>
00026 #include <decaf/util/NoSuchElementException.h>
00027 #include <decaf/util/AbstractSet.h>
00028 #include <decaf/util/AbstractCollection.h>
00029 #include <decaf/util/concurrent/Synchronizable.h>
00030 #include <decaf/util/concurrent/Mutex.h>
00031 #include <decaf/util/Map.h>
00032 #include <decaf/util/Collection.h>
00033 #include <decaf/util/Set.h>
00034 #include <decaf/util/Iterator.h>
00035
00036 namespace decaf{
00037 namespace util{
00038
00046 template <typename K, typename V, typename COMPARATOR = std::less<K> >
00047 class StlMap : public Map<K, V> {
00048 private:
00049
00050 std::map<K,V,COMPARATOR> valueMap;
00051 mutable concurrent::Mutex mutex;
00052 int modCount;
00053
00054 private:
00055
00056 class AbstractMapIterator {
00057 protected:
00058
00059 mutable int position;
00060 int expectedModCount;
00061 typename std::map<K,V,COMPARATOR>::iterator futureEntry;
00062 typename std::map<K,V,COMPARATOR>::iterator currentEntry;
00063
00064 StlMap* associatedMap;
00065
00066 private:
00067
00068 AbstractMapIterator(const AbstractMapIterator&);
00069 AbstractMapIterator& operator= (const AbstractMapIterator&);
00070
00071 public:
00072
00073 AbstractMapIterator(StlMap* parent) : position(0),
00074 expectedModCount(parent->modCount),
00075 futureEntry(parent->valueMap.begin()),
00076 currentEntry(parent->valueMap.end()),
00077 associatedMap(parent) {
00078 }
00079
00080 virtual ~AbstractMapIterator() {}
00081
00082 virtual bool checkHasNext() const {
00083 if (futureEntry != this->associatedMap->valueMap.end()) {
00084 return true;
00085 }
00086 return false;
00087 }
00088
00089 void checkConcurrentMod() const {
00090 if (expectedModCount != this->associatedMap->modCount) {
00091 throw ConcurrentModificationException(
00092 __FILE__, __LINE__, "StlMap modified outside this iterator");
00093 }
00094 }
00095
00096 void makeNext() {
00097 checkConcurrentMod();
00098
00099 if (!checkHasNext()) {
00100 throw NoSuchElementException(__FILE__, __LINE__, "No next element");
00101 }
00102
00103 currentEntry = futureEntry;
00104 futureEntry++;
00105 }
00106
00107 virtual void doRemove() {
00108
00109 checkConcurrentMod();
00110
00111 if (currentEntry == this->associatedMap->valueMap.end()) {
00112 throw decaf::lang::exceptions::IllegalStateException(
00113 __FILE__, __LINE__, "Remove called before call to next()");
00114 }
00115
00116 this->associatedMap->valueMap.erase(currentEntry);
00117 currentEntry = this->associatedMap->valueMap.end();
00118
00119 expectedModCount++;
00120 associatedMap->modCount++;
00121 }
00122 };
00123
00124 class EntryIterator : public Iterator< MapEntry<K,V> >, public AbstractMapIterator {
00125 private:
00126
00127 EntryIterator(const EntryIterator&);
00128 EntryIterator& operator= (const EntryIterator&);
00129
00130 public:
00131
00132 EntryIterator(StlMap* parent) : AbstractMapIterator(parent) {
00133 }
00134
00135 virtual ~EntryIterator() {}
00136
00137 virtual bool hasNext() const {
00138 return this->checkHasNext();
00139 }
00140
00141 virtual MapEntry<K, V> next() {
00142 this->makeNext();
00143 return MapEntry<K, V>(this->currentEntry->first, this->currentEntry->second);
00144 }
00145
00146 virtual void remove() {
00147 this->doRemove();
00148 }
00149 };
00150
00151 class KeyIterator : public Iterator<K>, public AbstractMapIterator {
00152 private:
00153
00154 KeyIterator(const KeyIterator&);
00155 KeyIterator& operator= (const KeyIterator&);
00156
00157 public:
00158
00159 KeyIterator(StlMap* parent) : AbstractMapIterator(parent) {
00160 }
00161
00162 virtual ~KeyIterator() {}
00163
00164 virtual bool hasNext() const {
00165 return this->checkHasNext();
00166 }
00167
00168 virtual K next() {
00169 this->makeNext();
00170 return this->currentEntry->first;
00171 }
00172
00173 virtual void remove() {
00174 this->doRemove();
00175 }
00176 };
00177
00178 class ValueIterator : public Iterator<V>, public AbstractMapIterator {
00179 private:
00180
00181 ValueIterator(const ValueIterator&);
00182 ValueIterator& operator= (const ValueIterator&);
00183
00184 public:
00185
00186 ValueIterator(StlMap* parent) : AbstractMapIterator(parent) {
00187 }
00188
00189 virtual ~ValueIterator() {}
00190
00191 virtual bool hasNext() const {
00192 return this->checkHasNext();
00193 }
00194
00195 virtual V next() {
00196 this->makeNext();
00197 return this->currentEntry->second;
00198 }
00199
00200 virtual void remove() {
00201 this->doRemove();
00202 }
00203 };
00204
00205 private:
00206
00207 class ConstAbstractMapIterator {
00208 protected:
00209
00210 mutable int position;
00211 int expectedModCount;
00212 typename std::map<K,V,COMPARATOR>::const_iterator futureEntry;
00213 typename std::map<K,V,COMPARATOR>::const_iterator currentEntry;
00214
00215 const StlMap* associatedMap;
00216
00217 private:
00218
00219 ConstAbstractMapIterator(const ConstAbstractMapIterator&);
00220 ConstAbstractMapIterator& operator= (const ConstAbstractMapIterator&);
00221
00222 public:
00223
00224 ConstAbstractMapIterator(const StlMap* parent) : position(0),
00225 expectedModCount(parent->modCount),
00226 futureEntry(parent->valueMap.begin()),
00227 currentEntry(parent->valueMap.end()),
00228 associatedMap(parent) {
00229 }
00230
00231 virtual ~ConstAbstractMapIterator() {}
00232
00233 virtual bool checkHasNext() const {
00234 if (futureEntry != this->associatedMap->valueMap.end()) {
00235 return true;
00236 }
00237 return false;
00238 }
00239
00240 void checkConcurrentMod() const {
00241 if (expectedModCount != this->associatedMap->modCount) {
00242 throw ConcurrentModificationException(
00243 __FILE__, __LINE__, "StlMap modified outside this iterator");
00244 }
00245 }
00246
00247 void makeNext() {
00248 checkConcurrentMod();
00249
00250 if (!checkHasNext()) {
00251 throw NoSuchElementException(__FILE__, __LINE__, "No next element");
00252 }
00253
00254 currentEntry = futureEntry;
00255 futureEntry++;
00256 }
00257 };
00258
00259 class ConstEntryIterator : public Iterator< MapEntry<K,V> >, public ConstAbstractMapIterator {
00260 private:
00261
00262 ConstEntryIterator(const ConstEntryIterator&);
00263 ConstEntryIterator& operator= (const ConstEntryIterator&);
00264
00265 public:
00266
00267 ConstEntryIterator(const StlMap* parent) : ConstAbstractMapIterator(parent) {
00268 }
00269
00270 virtual ~ConstEntryIterator() {}
00271
00272 virtual bool hasNext() const {
00273 return this->checkHasNext();
00274 }
00275
00276 virtual MapEntry<K, V> next() {
00277 this->makeNext();
00278 return MapEntry<K, V>(this->currentEntry->first, this->currentEntry->second);
00279 }
00280
00281 virtual void remove() {
00282 throw lang::exceptions::UnsupportedOperationException(
00283 __FILE__, __LINE__, "Cannot write to a const Iterator." );
00284 }
00285 };
00286
00287 class ConstKeyIterator : public Iterator<K>, public ConstAbstractMapIterator {
00288 private:
00289
00290 ConstKeyIterator(const ConstKeyIterator&);
00291 ConstKeyIterator& operator= (const ConstKeyIterator&);
00292
00293 public:
00294
00295 ConstKeyIterator(const StlMap* parent) : ConstAbstractMapIterator(parent) {
00296 }
00297
00298 virtual ~ConstKeyIterator() {}
00299
00300 virtual bool hasNext() const {
00301 return this->checkHasNext();
00302 }
00303
00304 virtual K next() {
00305 this->makeNext();
00306 return this->currentEntry->first;
00307 }
00308
00309 virtual void remove() {
00310 throw lang::exceptions::UnsupportedOperationException(
00311 __FILE__, __LINE__, "Cannot write to a const Iterator." );
00312 }
00313 };
00314
00315 class ConstValueIterator : public Iterator<V>, public ConstAbstractMapIterator {
00316 private:
00317
00318 ConstValueIterator(const ConstValueIterator&);
00319 ConstValueIterator& operator= (const ConstValueIterator&);
00320
00321 public:
00322
00323 ConstValueIterator(const StlMap* parent) : ConstAbstractMapIterator(parent) {
00324 }
00325
00326 virtual ~ConstValueIterator() {}
00327
00328 virtual bool hasNext() const {
00329 return this->checkHasNext();
00330 }
00331
00332 virtual V next() {
00333 this->makeNext();
00334 return this->currentEntry->second;
00335 }
00336
00337 virtual void remove() {
00338 throw lang::exceptions::UnsupportedOperationException(
00339 __FILE__, __LINE__, "Cannot write to a const Iterator." );
00340 }
00341 };
00342
00343 private:
00344
00345
00346 class StlMapEntrySet : public AbstractSet< MapEntry<K, V> > {
00347 private:
00348
00349 StlMap* associatedMap;
00350
00351 private:
00352
00353 StlMapEntrySet(const StlMapEntrySet&);
00354 StlMapEntrySet& operator= (const StlMapEntrySet&);
00355
00356 public:
00357
00358 StlMapEntrySet(StlMap* parent) : AbstractSet< MapEntry<K,V> >(), associatedMap(parent) {
00359 }
00360
00361 virtual ~StlMapEntrySet() {}
00362
00363 virtual int size() const {
00364 return associatedMap->size();
00365 }
00366
00367 virtual void clear() {
00368 associatedMap->clear();
00369 }
00370
00371 virtual bool remove(const MapEntry<K,V>& entry) {
00372 if (this->associatedMap->containsKey(entry.getKey()) &&
00373 this->associatedMap->get(entry.getKey()) == entry.getValue()) {
00374 associatedMap->remove(entry.getKey());
00375 return true;
00376 }
00377
00378 return false;
00379 }
00380
00381 virtual bool contains(const MapEntry<K,V>& entry) {
00382 if (this->associatedMap->containsKey(entry.getKey()) &&
00383 this->associatedMap->get(entry.getKey()) == entry.getValue()) {
00384 return true;
00385 }
00386 return false;
00387 }
00388
00389 virtual Iterator< MapEntry<K, V> >* iterator() {
00390 return new EntryIterator(associatedMap);
00391 }
00392
00393 virtual Iterator< MapEntry<K, V> >* iterator() const {
00394 return new ConstEntryIterator(associatedMap);
00395 }
00396 };
00397
00398
00399 class ConstStlMapEntrySet : public AbstractSet< MapEntry<K, V> > {
00400 private:
00401
00402 const StlMap* associatedMap;
00403
00404 private:
00405
00406 ConstStlMapEntrySet(const ConstStlMapEntrySet&);
00407 ConstStlMapEntrySet& operator= (const ConstStlMapEntrySet&);
00408
00409 public:
00410
00411 ConstStlMapEntrySet(const StlMap* parent) : AbstractSet< MapEntry<K,V> >(), associatedMap(parent) {
00412 }
00413
00414 virtual ~ConstStlMapEntrySet() {}
00415
00416 virtual int size() const {
00417 return associatedMap->size();
00418 }
00419
00420 virtual void clear() {
00421 throw decaf::lang::exceptions::UnsupportedOperationException(
00422 __FILE__, __LINE__, "Can't clear a const collection");
00423 }
00424
00425 virtual bool remove(const MapEntry<K,V>& entry DECAF_UNUSED) {
00426 throw decaf::lang::exceptions::UnsupportedOperationException(
00427 __FILE__, __LINE__, "Can't remove from const collection");
00428 }
00429
00430 virtual bool contains(const MapEntry<K,V>& entry) {
00431 if (this->associatedMap->containsKey(entry.getKey()) &&
00432 this->associatedMap->get(entry.getKey()) == entry.getValue()) {
00433 return true;
00434 }
00435 return false;
00436 }
00437
00438 virtual Iterator< MapEntry<K, V> >* iterator() {
00439 throw decaf::lang::exceptions::UnsupportedOperationException(
00440 __FILE__, __LINE__, "Can't return a non-const iterator for a const collection");
00441 }
00442
00443 virtual Iterator< MapEntry<K, V> >* iterator() const {
00444 return new ConstEntryIterator(associatedMap);
00445 }
00446 };
00447
00448 private:
00449
00450 class StlMapKeySet : public AbstractSet<K> {
00451 private:
00452
00453 StlMap* associatedMap;
00454
00455 private:
00456
00457 StlMapKeySet(const StlMapKeySet&);
00458 StlMapKeySet& operator= (const StlMapKeySet&);
00459
00460 public:
00461
00462 StlMapKeySet(StlMap* parent) : AbstractSet<K>(), associatedMap(parent) {
00463 }
00464
00465 virtual ~StlMapKeySet() {}
00466
00467 virtual bool contains(const K& key) const {
00468 return this->associatedMap->containsKey(key);
00469 }
00470
00471 virtual int size() const {
00472 return this->associatedMap->size();
00473 }
00474
00475 virtual void clear() {
00476 this->associatedMap->clear();
00477 }
00478
00479 virtual bool remove(const K& key) {
00480 if (this->associatedMap->containsKey(key)) {
00481 associatedMap->remove(key);
00482 return true;
00483 }
00484 return false;
00485 }
00486
00487 virtual Iterator<K>* iterator() {
00488 return new KeyIterator(this->associatedMap);
00489 }
00490
00491 virtual Iterator<K>* iterator() const {
00492 return new ConstKeyIterator(this->associatedMap);
00493 }
00494 };
00495
00496 class ConstStlMapKeySet : public AbstractSet<K> {
00497 private:
00498
00499 const StlMap* associatedMap;
00500
00501 private:
00502
00503 ConstStlMapKeySet(const ConstStlMapKeySet&);
00504 ConstStlMapKeySet& operator= (const ConstStlMapKeySet&);
00505
00506 public:
00507
00508 ConstStlMapKeySet(const StlMap* parent) : AbstractSet<K>(), associatedMap(parent) {
00509 }
00510
00511 virtual ~ConstStlMapKeySet() {}
00512
00513 virtual bool contains(const K& key) const {
00514 return this->associatedMap->containsKey(key);
00515 }
00516
00517 virtual int size() const {
00518 return this->associatedMap->size();
00519 }
00520
00521 virtual void clear() {
00522 throw decaf::lang::exceptions::UnsupportedOperationException(
00523 __FILE__, __LINE__, "Can't modify a const collection");
00524 }
00525
00526 virtual bool remove(const K& key DECAF_UNUSED) {
00527 throw decaf::lang::exceptions::UnsupportedOperationException(
00528 __FILE__, __LINE__, "Can't modify a const collection");
00529 }
00530
00531 virtual Iterator<K>* iterator() {
00532 throw decaf::lang::exceptions::UnsupportedOperationException(
00533 __FILE__, __LINE__, "Can't return a non-const iterator for a const collection");
00534 }
00535
00536 virtual Iterator<K>* iterator() const {
00537 return new ConstKeyIterator(this->associatedMap);
00538 }
00539 };
00540
00541 private:
00542
00543 class StlMapValueCollection : public AbstractCollection<V> {
00544 private:
00545
00546 StlMap* associatedMap;
00547
00548 private:
00549
00550 StlMapValueCollection(const StlMapValueCollection&);
00551 StlMapValueCollection& operator= (const StlMapValueCollection&);
00552
00553 public:
00554
00555 StlMapValueCollection(StlMap* parent) : AbstractCollection<V>(), associatedMap(parent) {
00556 }
00557
00558 virtual ~StlMapValueCollection() {}
00559
00560 virtual bool contains(const V& value) const {
00561 return this->associatedMap->containsValue(value);
00562 }
00563
00564 virtual int size() const {
00565 return this->associatedMap->size();
00566 }
00567
00568 virtual void clear() {
00569 this->associatedMap->clear();
00570 }
00571
00572 virtual Iterator<V>* iterator() {
00573 return new ValueIterator(this->associatedMap);
00574 }
00575
00576 virtual Iterator<V>* iterator() const {
00577 return new ConstValueIterator(this->associatedMap);
00578 }
00579 };
00580
00581 class ConstStlMapValueCollection : public AbstractCollection<V> {
00582 private:
00583
00584 const StlMap* associatedMap;
00585
00586 private:
00587
00588 ConstStlMapValueCollection(const ConstStlMapValueCollection&);
00589 ConstStlMapValueCollection& operator= (const ConstStlMapValueCollection&);
00590
00591 public:
00592
00593 ConstStlMapValueCollection(const StlMap* parent) : AbstractCollection<V>(), associatedMap(parent) {
00594 }
00595
00596 virtual ~ConstStlMapValueCollection() {}
00597
00598 virtual bool contains(const V& value) const {
00599 return this->associatedMap->containsValue(value);
00600 }
00601
00602 virtual int size() const {
00603 return this->associatedMap->size();
00604 }
00605
00606 virtual void clear() {
00607 throw decaf::lang::exceptions::UnsupportedOperationException(
00608 __FILE__, __LINE__, "Can't modify a const collection");
00609 }
00610
00611 virtual Iterator<V>* iterator() {
00612 throw decaf::lang::exceptions::UnsupportedOperationException(
00613 __FILE__, __LINE__, "Can't return a non-const iterator for a const collection");
00614 }
00615
00616 virtual Iterator<V>* iterator() const {
00617 return new ConstValueIterator(this->associatedMap);
00618 }
00619 };
00620
00621 private:
00622
00623
00624 decaf::lang::Pointer<StlMapEntrySet> cachedEntrySet;
00625 decaf::lang::Pointer<StlMapKeySet> cachedKeySet;
00626 decaf::lang::Pointer<StlMapValueCollection> cachedValueCollection;
00627
00628
00629 mutable decaf::lang::Pointer<ConstStlMapEntrySet> cachedConstEntrySet;
00630 mutable decaf::lang::Pointer<ConstStlMapKeySet> cachedConstKeySet;
00631 mutable decaf::lang::Pointer<ConstStlMapValueCollection> cachedConstValueCollection;
00632
00633 public:
00634
00638 StlMap() : Map<K,V>(), valueMap(), mutex(), modCount(0),
00639 cachedEntrySet(), cachedKeySet(), cachedValueCollection(),
00640 cachedConstEntrySet(), cachedConstKeySet(), cachedConstValueCollection() {
00641 }
00642
00649 StlMap(const StlMap& source ) : Map<K,V>(), valueMap(), mutex(), modCount(0),
00650 cachedEntrySet(), cachedKeySet(), cachedValueCollection(),
00651 cachedConstEntrySet(), cachedConstKeySet(), cachedConstValueCollection() {
00652 copy(source);
00653 }
00654
00661 StlMap(const Map<K,V>& source) : Map<K,V>(), valueMap(), mutex(), modCount(0),
00662 cachedEntrySet(), cachedKeySet(), cachedValueCollection(),
00663 cachedConstEntrySet(), cachedConstKeySet(), cachedConstValueCollection() {
00664 copy(source);
00665 }
00666
00667 virtual ~StlMap() {}
00668
00672 virtual bool equals(const StlMap& source) const {
00673 return this->valueMap == source.valueMap;
00674 }
00675
00679 virtual bool equals(const Map<K,V>& source) const {
00680 typename std::auto_ptr< Iterator<K> > iterator(this->keySet().iterator());
00681 while (iterator->hasNext()) {
00682 K key = iterator->next();
00683 if (!this->containsKey(key)) {
00684 return false;
00685 }
00686
00687 if (!(this->get(key) == source.get(key))) {
00688 return false;
00689 }
00690 }
00691
00692 return true;
00693 }
00694
00698 virtual void copy(const StlMap& source) {
00699 this->valueMap.clear();
00700 this->valueMap.insert( source.valueMap.begin(), source.valueMap.end() );
00701 }
00702
00706 virtual void copy(const Map<K, V>& source) {
00707 this->clear();
00708 this->putAll(source);
00709 }
00710
00714 virtual void clear() {
00715 valueMap.clear();
00716 }
00717
00721 virtual bool containsKey(const K& key) const {
00722 if (valueMap.empty()) {
00723 return false;
00724 }
00725
00726 typename std::map<K, V, COMPARATOR>::const_iterator iter;
00727 iter = valueMap.find(key);
00728 return iter != valueMap.end();
00729 }
00730
00734 virtual bool containsValue(const V& value) const {
00735 if (valueMap.empty()) {
00736 return false;
00737 }
00738
00739 typename std::map<K, V, COMPARATOR>::const_iterator iter = valueMap.begin();
00740 for (; iter != valueMap.end(); ++iter) {
00741 if ((*iter).second == value) {
00742 return true;
00743 }
00744 }
00745
00746 return false;
00747 }
00748
00752 virtual bool isEmpty() const {
00753 return valueMap.empty();
00754 }
00755
00759 virtual int size() const {
00760 return (int)valueMap.size();
00761 }
00762
00766 virtual V& get(const K& key) {
00767 typename std::map<K, V, COMPARATOR>::iterator iter;
00768 iter = valueMap.find(key);
00769 if (iter == valueMap.end()) {
00770 throw NoSuchElementException(__FILE__, __LINE__, "Key does not exist in map");
00771 }
00772
00773 return iter->second;
00774 }
00775
00779 virtual const V& get(const K& key) const {
00780 typename std::map<K, V, COMPARATOR>::const_iterator iter;
00781 iter = valueMap.find(key);
00782 if (iter == valueMap.end()) {
00783 throw NoSuchElementException(__FILE__, __LINE__, "Key does not exist in map");
00784 }
00785
00786 return iter->second;
00787 }
00788
00792 virtual bool put(const K& key, const V& value) {
00793 bool result = false;
00794 if (this->containsKey(key)) {
00795 result = true;
00796 }
00797 valueMap[key] = value;
00798 modCount++;
00799 return result;
00800 }
00801
00805 virtual bool put(const K& key, const V& value, V& oldValue) {
00806 bool result = false;
00807 if (this->containsKey(key)) {
00808 result = true;
00809 oldValue = valueMap[key];
00810 }
00811 valueMap[key] = value;
00812 modCount++;
00813 return result;
00814 }
00815
00819 virtual void putAll(const StlMap<K, V, COMPARATOR>& other) {
00820 this->valueMap.insert(other.valueMap.begin(), other.valueMap.end());
00821 this->modCount++;
00822 }
00823
00827 virtual void putAll(const Map<K, V>& other) {
00828 typename std::auto_ptr< Iterator<K> > iterator(other.keySet().iterator());
00829 while (iterator->hasNext()) {
00830 K key = iterator->next();
00831 this->put(key, other.get(key));
00832 }
00833 }
00834
00838 virtual V remove(const K& key) {
00839
00840 typename std::map<K, V, COMPARATOR>::iterator iter = valueMap.find(key);
00841 if (iter == valueMap.end()) {
00842 throw NoSuchElementException(
00843 __FILE__, __LINE__, "Key is not present in this Map.");
00844 }
00845
00846 V result = iter->second;
00847 valueMap.erase(iter);
00848 modCount++;
00849 return result;
00850 }
00851
00852 virtual Set< MapEntry<K, V> >& entrySet() {
00853 if (this->cachedEntrySet == NULL) {
00854 this->cachedEntrySet.reset(new StlMapEntrySet(this));
00855 }
00856 return *(this->cachedEntrySet);
00857 }
00858 virtual const Set< MapEntry<K, V> >& entrySet() const {
00859 if (this->cachedConstEntrySet == NULL) {
00860 this->cachedConstEntrySet.reset(new ConstStlMapEntrySet(this));
00861 }
00862 return *(this->cachedConstEntrySet);
00863 }
00864
00865 virtual Set<K>& keySet() {
00866 if (this->cachedKeySet == NULL) {
00867 this->cachedKeySet.reset(new StlMapKeySet(this));
00868 }
00869 return *(this->cachedKeySet);
00870 }
00871
00872 virtual const Set<K>& keySet() const {
00873 if (this->cachedConstKeySet == NULL) {
00874 this->cachedConstKeySet.reset(new ConstStlMapKeySet(this));
00875 }
00876 return *(this->cachedConstKeySet);
00877 }
00878
00879 virtual Collection<V>& values() {
00880 if (this->cachedValueCollection == NULL) {
00881 this->cachedValueCollection.reset(new StlMapValueCollection(this));
00882 }
00883 return *(this->cachedValueCollection);
00884 }
00885
00886 virtual const Collection<V>& values() const {
00887 if (this->cachedConstValueCollection == NULL) {
00888 this->cachedConstValueCollection.reset(new ConstStlMapValueCollection(this));
00889 }
00890 return *(this->cachedConstValueCollection);
00891 }
00892
00893 public:
00894
00895 virtual void lock() {
00896 mutex.lock();
00897 }
00898
00899 virtual bool tryLock() {
00900 return mutex.tryLock();
00901 }
00902
00903 virtual void unlock() {
00904 mutex.unlock();
00905 }
00906
00907 virtual void wait() {
00908 mutex.wait();
00909 }
00910
00911 virtual void wait( long long millisecs ) {
00912 mutex.wait( millisecs );
00913 }
00914
00915 virtual void wait( long long millisecs, int nanos ) {
00916 mutex.wait( millisecs, nanos );
00917 }
00918
00919 virtual void notify() {
00920 mutex.notify();
00921 }
00922
00923 virtual void notifyAll() {
00924 mutex.notifyAll();
00925 }
00926
00927 };
00928
00929 }}
00930
00931 #endif