00001 #ifndef STATICPOOL_HPP_INCLUDED
00002 #define STATICPOOL_HPP_INCLUDED
00003
00004 #include <vector>
00005
00006 #include <cassert>
00007 #include <string.h>
00008 #include <fstream>
00009 #include <iostream>
00010 #include <algorithm>
00011 #include <stack>
00012
00013
00014
00015
00022 #include "../Common.h"
00023 #include "VtsSqId.hpp"
00024
00025 class hHybridMesh;
00026
00027 template< class BaseT, int TMaxVerts = BaseT::nVerts>
00028 class StaticPool
00029 {
00030 public:
00031
00032
00033 typedef VtsSqId<TMaxVerts> VtsId;
00034 typedef unordered_map< VtsId, uTind> HashPosByVts;
00035 typedef typename HashPosByVts::value_type VtsPos;
00036 typedef typename HashPosByVts::iterator Vts2posIter;
00037 typedef typename HashPosByVts::const_iterator Vts2posCIter;
00038
00039 typedef BaseT* BaseTPtr;
00040 private:
00041 static const int MaxVerts = TMaxVerts;
00042 uTind hashSize_;
00043 uTind capacity_;
00044 uTind size_;
00045 uTlong capacityB_;
00046 BYTE* poolB_;
00047 BYTE* endB_;
00048 BaseTPtr *hash_;
00049 uTind uniqueID_;
00050 Tlong memoryChangeB_;
00051 Tind capacityChange_;
00052 std::stack<uTind> emptyPos_;
00053
00054 hHybridMesh * m;
00055
00056 uTind uniqueID()
00057 {
00058 uTind new_id = ++uniqueID_;
00059 updateHashSize() ;
00060 return new_id;
00061 }
00062
00063 public:
00064 uTind dividedObjs_;
00065
00066 HashPosByVts vts2pos_;
00067
00068 StaticPool(hHybridMesh * mesh): m(mesh), hashSize_(0),capacity_(0),size_(0),capacityB_(0),poolB_(NULL),endB_(NULL),hash_(NULL),uniqueID_(0),memoryChangeB_(0),capacityChange_(0), dividedObjs_(0)
00069 {
00070 clear();
00071 }
00072
00073 ~StaticPool()
00074 {
00075 clear();
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 uTind last() const {
00085 return uniqueID_;
00086 }
00087 BaseT* end() const {
00088 return reinterpret_cast<BaseTPtr>(endB_);
00089 }
00090 uTind size() const {
00091 return size_;
00092 }
00093 uTind capacity() const {
00094 return capacity_;
00095 }
00096
00097 bool empty() const {
00098 return (size_ == 0);
00099 }
00100
00101 void clear()
00102 {
00103 vts2pos_.clear();
00104 while( emptyPos_.size() > 0) {
00105 emptyPos_.pop();
00106
00107 }
00108
00109 uniqueID_ = 0;
00110 capacity_ = 0;
00111 updateHashSize();
00112 size_ = 0;
00113 safeDeleteArray(hash_);
00114 hash_ = NULL;
00115
00116 capacityB_ = 0;
00117 endB_ = NULL;
00118 safeDeleteArray(poolB_);
00119 poolB_ = NULL;
00120
00121 dividedObjs_=0;
00122 }
00123
00124 void reserve(const uTind newCapacity,uTind newCapacityB=0, bool forceResize = false)
00125 {
00126
00127
00128 if (newCapacity > 0) {
00129 capacity_ = newCapacity;
00130 updateHashSize();
00131 if (newCapacityB == 0) {
00132 newCapacityB = sizeof(BaseT)*newCapacity;
00133 }
00134
00135 if (newCapacityB > capacityB_ || forceResize) {
00136 const uTind oldSizeB(static_cast<uTind>(endB_ - poolB_));
00137 assert(oldSizeB <= capacityB_);
00138 const uTind oldCapacityB(capacityB_);
00139 BYTE * _newPool(NULL);
00140 try
00141 {
00142 capacityB_ = newCapacityB;
00143 _newPool = new BYTE[capacityB_+sizeof(BaseT)];
00144 memset(_newPool,0,capacityB_+sizeof(BaseT));
00145 }
00146 catch (const std::bad_alloc & e)
00147 {
00148 std::string msg(e.what());
00149 msg.append(" StaticPool::resize( ");
00150 char tmp[64]={};
00151
00152 msg.append(tmp);
00153 msg.append(", ");
00154
00155 msg.append(tmp);
00156 msg.append(") not enough memory to resize pool.");
00157 std::bad_alloc err;
00158 throw err;
00159 }
00160
00161 if (poolB_ != NULL) {
00162 if (forceResize && newCapacityB < oldCapacityB) {
00163 memcpy(_newPool,poolB_,newCapacityB);
00164 endB_ = _newPool+newCapacityB;
00165 }
00166 else {
00167 memcpy(_newPool,poolB_,oldSizeB);
00168 endB_ = _newPool+oldSizeB;
00169 }
00170 safeDeleteArray(poolB_);
00171 }
00172 else {
00173 endB_=_newPool;
00174 }
00175 poolB_ = _newPool;
00176 _newPool = NULL;
00177 rebuildHash();
00178 }
00179 }
00180 }
00181
00182 void reallocate(const uTind newCapacity,uTlong newCapacityB=0, bool forceResize = false)
00183 {
00184
00185
00186
00187 if (newCapacity > 0)
00188 {
00189
00190 capacity_ = newCapacity;
00191 updateHashSize();
00192 if (newCapacityB == 0)
00193 {
00194 newCapacityB = sizeof(BaseT)*newCapacity;
00195 }
00196
00197 assert(newCapacityB / capacity_ >= sizeof(BaseT));
00198
00199
00200 if (newCapacityB > capacityB_ || forceResize)
00201 {
00202
00203 BYTE * _newPool(NULL);
00204 try
00205 {
00206 capacityB_ = newCapacityB;
00207 _newPool = new BYTE[capacityB_+sizeof(BaseT)];
00208 memset(_newPool,0,capacityB_+sizeof(BaseT));
00209
00210
00211
00212
00213 rebuildHash();
00214 }
00215 catch (const std::bad_alloc & e)
00216 {
00217 std::string msg(e.what());
00218 msg.append(" StaticPool::reallocate(newCapacity=");
00219 char tmp[64]={};
00220
00221 msg.append(tmp);
00222 msg.append(", newCapacityB=");
00223
00224 msg.append(tmp);
00225 msg.append(") not enough memory to resize pool.");
00226 std::bad_alloc err;
00227 throw err;
00228 }
00229
00230 if (poolB_ != NULL)
00231 {
00232
00233 size_t offset(0);
00234 BaseTPtr oldEndIt(reinterpret_cast<BaseT*>(endB_));
00235 BYTE* _oldPool(poolB_);
00236 poolB_ = _newPool;
00237 endB_ = poolB_;
00238 for(BaseTPtr it(reinterpret_cast<BaseTPtr>(_oldPool)); it < oldEndIt;
00239 it = reinterpret_cast<BaseTPtr>(it->next()) )
00240 {
00241 BaseTPtr moved_obj(reinterpret_cast<BaseTPtr>(endB_));
00242 assert(moved_obj != NULL);
00243 if(it->nMyClassSons_ != BaseT::delMark) {
00244
00245 memcpy(moved_obj,it,it->mySize_);
00246 hash_[moved_obj->pos_]=reinterpret_cast<BaseTPtr>(moved_obj);
00247 offset+=moved_obj->mySize_;
00248
00249 switch (moved_obj->nMyClassSons_)
00250 {
00251 case BaseT::fullRefMark:
00252 case BaseT::partialRefMark:
00253 offset += moved_obj->hBreak(m);
00254
00255 break;
00256 case BaseT::derefMark:
00257 assert(!"Deref mark found while reallocationg!");
00258 moved_obj->derefine(m);
00259 break;
00260 }
00261 endB_ = poolB_+offset;
00262 moved_obj->updatePointers();
00263 assert(it->equals(*moved_obj));
00264 }
00265 else {
00266 --size_;
00267 hash_[it->pos_] = NULL;
00268 emptyPos_.push(it->pos_);
00269
00270
00271 }
00272
00273 }
00274 rebuildVts2Pos();
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 safeDeleteArray(_oldPool);
00290 }
00291 else
00292 {
00293 endB_=poolB_;
00294 }
00295 }
00296 }
00297 else {
00298 this->clear();
00299 }
00300 checkHash();
00301 if(size_ != 0) {
00302 assert(capacityB_ / size_ >= sizeof(BaseT));
00303 }
00304 if(capacity_ != 0){
00305 assert(capacityB_ / capacity_ >= sizeof(BaseT));
00306 }
00307 assert(endB_ >= poolB_);
00308 assert(endB_ <= poolB_+newCapacityB);
00309 assert(static_cast<uTind>(endB_-poolB_) <= capacityB_);
00310 assert(size_ <= capacity_);
00311 }
00312
00313 void rebuildVts2Pos()
00314 {
00315 #ifndef _MSC_VER
00316 if(MaxVerts > 0)
00317 #endif
00318 {
00319 vts2pos_.clear();
00320 for(constIterator<> it(this); !it.done(); ++it) {
00321 uTind verts[VtsId::length];
00322 uTind i(0);
00323 for(;i < it->typeSpecyfic_.nVerts_;++i) {
00324 verts[i]=it->verts(i);
00325 }
00326 for(;i < static_cast<uTind>(VtsId::length); ++i) {
00327 verts[i]=UNKNOWN;
00328 }
00329 assert(i == static_cast<uTind>(VtsId::length));
00330 assert(vts2pos_.find(verts) == vts2pos_.end());
00331
00332 vts2pos_.insert(VtsPos(verts,it->pos_));
00333
00334 VtsId tmpId(verts);
00335 assert(vts2pos_.count(VtsId(verts))==1);
00336 Vts2posIter iter = vts2pos_.find(VtsId(verts));
00337 assert( iter != vts2pos_.end());
00338 assert( tmpId == iter->first );
00339 assert(iter->second == it->pos_);
00340 }
00341 }
00342 }
00343
00344 inline uTind hashSize() const { return hashSize_; }
00345 void updateHashSize() { hashSize_ = (capacity_==0) ? 0 : FIRST + std::max(capacity_,uniqueID_); }
00346
00347 void rebuildHash()
00348 {
00349 safeDeleteArray(hash_);
00350 if (capacity_ > 0)
00351 {
00352 try
00353 {
00354 this->hash_ = new BaseTPtr[hashSize()];
00355 memset(hash_, 0, sizeof(BaseTPtr) * (hashSize()));
00356 }
00357 catch (const std::bad_alloc &)
00358 {
00359 throw "StaticPool::rebuildHash: not enugh memory to allocate";
00360 }
00361
00362
00363 assert(hash_[0] == NULL);
00364 for (Iterator<> it(this);!it.done();++it)
00365 {
00366 assert(it->pos_ >= FIRST);
00367 assert(it->pos_ <= hashSize());
00368 assert(hash_[it->pos_]== NULL);
00369
00370 hash_[it->pos_]= ⁢
00371 it->updatePointers();
00372
00373 assert(hash_[it->pos_]->pos_ == it->pos_);
00374 }
00375 }
00376 checkHash();
00377 }
00378
00379 void checkHash() const
00380 {
00381
00382 for(int i=0; i < hashSize(); ++i)
00383 {
00384 assert( (hash_[i] == NULL)
00385 || ( (reinterpret_cast<BYTE*>(hash_[i]) >= poolB_)
00386 && (reinterpret_cast<BYTE*>(hash_[i]) < endB_) ) );
00387 }
00388
00389 for(constIterator<allObj> it(this); !it.done(); ++it)
00390 {
00391 assert(getById(it->id_).id_== it->id_);
00392
00393 }
00394 }
00395
00396 BaseT & first()
00397 {
00398 assert(!empty());
00399 return *reinterpret_cast<BaseT*>(poolB_);
00400 }
00401
00402 const BaseT & first() const
00403 {
00404 assert(!empty());
00405 return *reinterpret_cast<const BaseT*>(poolB_);
00406 }
00407
00408 inline BaseT & at(const uTind pos_)
00409 {
00410 assert(pos_<= hashSize());
00411 assert(pos_ >= FIRST);
00412 assert(hash_[pos_] != NULL);
00413 assert(hash_[pos_]->pos_== pos_);
00414 return *hash_[pos_];
00415 }
00416
00417 template<class RetType>
00418 inline RetType & at(const uTind pos_)
00419 {
00420 assert(RetType::myType == hash_[pos_]->type_);
00421 assert(pos_<= hashSize());
00422 assert(pos_ >= FIRST);
00423 assert(hash_[pos_] != NULL);
00424 assert(hash_[pos_]->pos_== pos_);
00425 return *reinterpret_cast<RetType*>(hash_[pos_]);
00426 }
00427
00428 inline const BaseT & at(const uTind pos_) const
00429 {
00430 assert(pos_<= hashSize());
00431 assert(hash_[pos_]->pos_== pos_);
00432 return *hash_[pos_];
00433 }
00434
00435 template<class RetType>
00436 inline const RetType & at(const uTind pos_) const
00437 {
00438 assert(RetType::myType == hash_[pos_]->type_);
00439 assert(pos_<= hashSize());
00440 assert(hash_[pos_]->pos_== pos_);
00441 return *static_cast<RetType*>(hash_[pos_]);
00442 }
00443
00444 inline BaseT & getById(const ID id)
00445 {
00446 assert( at(BaseT::posFromId(id)).type_== BaseT::typeFromId(id));
00447 assert( at(BaseT::posFromId(id)).id_== id);
00448 return at(BaseT::posFromId(id));
00449 }
00450
00451 template<class RetType>
00452 inline RetType & getById(const ID id)
00453 {
00454
00455 assert( at(BaseT::posFromId(id)).type_== BaseT::typeFromId(id));
00456 assert( at(BaseT::posFromId(id)).id_== id);
00457 return at<RetType>(BaseT::posFromId(id));
00458 }
00459
00460 inline const BaseT & getById(const ID id) const
00461 {
00462 assert( at(BaseT::posFromId(id)).type_== BaseT::typeFromId(id));
00463 assert( at(BaseT::posFromId(id)).id_== id);
00464 return at(BaseT::posFromId(id));
00465 }
00466
00467 template<class RetType>
00468 inline const RetType & getById(const ID id) const
00469 {
00470 assert( at(BaseT::posFromId(id)).type_== BaseT::typeFromId(id));
00471 assert( at(BaseT::posFromId(id)).id_== id);
00472 return at<RetType>(BaseT::posFromId(id));
00473 }
00474
00475
00476 inline const BaseT& operator[](const Tind pos_) const
00477 {
00478 assert(pos_<= hashSize());
00479 assert(pos_ >= FIRST);
00480 return *hash_[pos_];
00481 }
00482 inline BaseT& operator[](const Tind pos_)
00483 {
00484 assert(pos_<= hashSize());
00485 assert(pos_ >= FIRST);
00486 return *hash_[pos_];
00487 }
00488
00489
00490 inline const BaseT& operator()(const ID id) const { return getById(id); }
00491 inline BaseT& operator()(const ID id) { return getById(id); }
00492
00493 private:
00494
00495 void checkIfInVts2Pos(const uTind verts[]) const
00496 {
00497 #ifndef _MSC_VER
00498 if(MaxVerts > 0)
00499 #endif
00500 {
00501 if(vts2pos_.find(VtsId(verts)) != vts2pos_.end() ) {
00502 mf_log_err("Duplicate object detected (max verts %d)!",MaxVerts);
00503 mf_print_array(verts,MaxVerts,"%d");
00504 }
00505
00506 }
00507 }
00508
00509 void insertIntoVts2Pos(const uTind verts[],const int pos)
00510 {
00511 #ifndef _MSC_VER
00512 if(MaxVerts > 0)
00513 #endif
00514 {
00515
00516
00517
00518 vts2pos_.insert( VtsPos(verts, static_cast<uTind>(pos) ) );
00519 assert(vts2pos_[verts] == pos);
00520 }
00521 }
00522
00523 public:
00524
00525
00526
00527 template< class T>
00528 T* newObj(hHybridMesh * myMesh,const uTind verts[],void * memPtr=NULL)
00529 {
00530 uTind objpos = -1;
00531 if(!emptyPos_.empty()) {
00532 objpos = emptyPos_.top();
00533 emptyPos_.pop();
00534 }
00535 else {
00536 objpos = (uniqueID());
00537 }
00538
00539 void * ptr(memPtr==NULL ? endB_ : memPtr);
00540 assert( objpos < hashSize());
00541 assert(usedMemory() < totalMemory());
00542 assert(hash_[objpos]==NULL);
00543 assert(ptr >= poolB_);
00544 assert(ptr < poolB_+capacityB_);
00545
00546 checkIfInVts2Pos(verts);
00547
00548 hash_[objpos] = reinterpret_cast<BaseT*>( new(ptr) T(myMesh,verts,objpos) );
00549 ++size_;
00550 if(memPtr == NULL) {
00551 endB_+=sizeof(T);
00552 }
00553
00554 insertIntoVts2Pos(verts,hash_[objpos]->pos_);
00555
00556 assert(uniqueID_ >= objpos);
00557 assert(usedMemory() <= totalMemory());
00558 assert(hash_[objpos] != NULL);
00559 assert( size_ <= FIRST+capacity_);
00560 return reinterpret_cast<T*>(hash_[objpos]);
00561 }
00562
00563 uTlong totalMemory() const
00564 {
00565 return capacityB_;
00566 }
00567
00568 uTlong usedMemory() const
00569 {
00570 assert(endB_ >= poolB_);
00571 return static_cast<uTlong>(endB_-poolB_);
00572 }
00573
00574 void requestChange(const Tind sizeChange,const Tlong memChange)
00575 {
00576 capacityChange_+=sizeChange;
00577 memoryChangeB_+=memChange;
00578 assert(static_cast<size_t>(memoryChangeB_ / capacityChange_) >= sizeof(BaseT));
00579 }
00580
00581 uTlong memoryNeeded() const
00582 {
00583 return usedMemory() + memoryChangeB_;
00584 }
00585
00586 void adjust()
00587 {
00590 if (memoryChangeB_!=0 || capacityChange_!= 0)
00591 {
00592 assert(memoryChangeB_ / capacityChange_ >= static_cast<Tlong>(sizeof(BaseT)));
00593 reallocate(size()+capacityChange_, memoryNeeded(),true);
00594 memoryChangeB_=0;
00595 capacityChange_=0;
00596 }
00597 }
00598
00599
00600 uTind nonDividedObjs() const
00601 {
00602 return size() - dividedObjs_;
00603 }
00604
00605
00606
00607
00608
00609
00610
00612
00613 std::ofstream & operator << (std::ofstream & stream)
00614 {
00615 return this->write(stream);
00616 }
00617
00618 std::ifstream & operator >> (std::ifstream & stream)
00619 {
00620 return this->read(stream);
00621 }
00623
00624 struct allObj
00625 {
00626 static bool check(const BaseT*) {return false;}
00627 };
00628 struct notBroken
00629 {
00630 static bool check(const BaseT* obj) { return obj->isBroken(); }
00631 };
00632 struct atBoundary
00633 {
00634 static bool check(const BaseT* obj) { return obj->isAtBoundary(); }
00635 };
00636
00637 template< class TCondition = allObj>
00638 class Iterator
00639 {
00640 public:
00641
00642 Iterator(StaticPool * container) : _container(container)
00643 {
00644 if (!_container->empty())
00645 {
00646 _obj = reinterpret_cast<BaseT*>(_container->poolB_);
00647 while(TCondition::check(_obj))
00648 {
00649 this->operator++();
00650 }
00651 }
00652 else
00653 {
00654 _obj = reinterpret_cast<BaseT*>(_container->endB_);
00655 }
00656 }
00657
00658 Iterator(StaticPool * container,const uTind pos_) : _container(container)
00659 {
00660 if (!container->empty() && pos_<= _container->last())
00661 {
00662 _obj = _container->at(pos_);
00663 }
00664 else
00665 {
00666 _obj = reinterpret_cast<BaseT*>(_container->endB_);
00667 }
00668 }
00669
00670 template< class T>
00671 T* as() {
00672 return reinterpret_cast<T*>(_obj);
00673 }
00674
00675 BaseT* operator&() {
00676 return _obj;
00677 }
00678 BaseT& operator*() {
00679 return *_obj;
00680 }
00681 BaseT* operator->() {
00682 return _obj;
00683 }
00684 BaseT* operator++()
00685 {
00686 assert(_obj->mySize_> 0);
00687 do{
00688 _obj = reinterpret_cast<BaseT*>( reinterpret_cast<BYTE*>(_obj) + _obj->mySize_ );
00689 }while(TCondition::check(_obj));
00690 assert(reinterpret_cast<BYTE*>(_obj) <= _container->endB_);
00691 return _obj;
00692 }
00693 BaseT* operator++(int)
00694 {
00695 const BaseT* old(_obj);
00696 operator++();
00697 return old;
00698 }
00699
00700 bool done() const {
00701 return (reinterpret_cast<BYTE*>(_obj) >= _container->endB_);
00702 }
00703 bool operator==(const Iterator & other) const {
00704 return _container==other._container && _obj==other._obj;
00705 }
00706 bool operator!=(const Iterator & other) const {
00707 return !(*this==other);
00708 }
00709
00710 private:
00711 StaticPool * _container;
00712 BaseT *_obj;
00713 };
00714
00715 template< class TCondition = allObj>
00716 class constIterator
00717 {
00718 public:
00719
00720 constIterator(const StaticPool * container) : _container(container)
00721 {
00722 if (!_container->empty())
00723 {
00724 _obj = reinterpret_cast<const BaseT*>(_container->poolB_);
00725 while(TCondition::check(_obj))
00726 {
00727 this->operator++();
00728 }
00729 }
00730 else
00731 {
00732 _obj = reinterpret_cast<const BaseT*>(_container->endB_);
00733 }
00734 }
00735
00736 constIterator(const StaticPool * container,const uTind pos_) : _container(container)
00737 {
00738 if (!container->empty() && pos_<= _container->last())
00739 {
00740 _obj = &_container->at(pos_);
00741 }
00742 else
00743 {
00744 _obj = reinterpret_cast<const BaseT*>(_container->endB_);
00745 }
00746 }
00747
00748 template< class T>
00749 const T* as() {
00750 return reinterpret_cast<const T*>(_obj);
00751 }
00752
00753 const BaseT* operator&() const {
00754 return _obj;
00755 }
00756 const BaseT& operator*() const {
00757 return *_obj;
00758 }
00759 const BaseT* operator->()const {
00760 return _obj;
00761 }
00762 const BaseT* operator++()
00763 {
00764 assert(_obj->mySize_> 0);
00765 do{
00766 _obj = reinterpret_cast<const BaseT*>( reinterpret_cast<const BYTE*>(_obj) + _obj->mySize_ );
00767 }while(TCondition::check(_obj));
00768 assert( reinterpret_cast<const BYTE*>(_obj) <= _container->endB_);
00769 return _obj;
00770 }
00771 const BaseT* operator++(int)
00772 {
00773 const BaseT* old(reinterpret_cast<const BaseT*>(_obj));
00774 operator++();
00775 return old;
00776 }
00777
00778 bool done() const {
00779 return (reinterpret_cast<const BYTE*>(_obj) >= _container->endB_);
00780 }
00781 bool operator==(const constIterator & other) const {
00782 return _container==other._container && _obj==other._obj;
00783 }
00784 bool operator!=(const constIterator & other) const {
00785 return !(*this==other);
00786 }
00787
00788 private:
00789 const StaticPool * _container;
00790 const BaseT * _obj;
00791 };
00792
00793 constIterator<notBroken> begin() const {
00794 return constIterator<notBroken>(this);
00795 }
00796
00797
00798 Iterator<notBroken> begin() {
00799 return Iterator<notBroken>(this);
00800 }
00801
00802
00803
00804 std::ostream& write(std::ostream& stream) const
00805 {
00806 if(stream.good())
00807 {
00808 stream << capacity_ << " "; assert(stream.good());
00809 stream << size_ << " "
00810 << capacityB_ << " "
00811 << (endB_-poolB_) << " "
00812 << uniqueID_ << " "
00813 << memoryChangeB_ << " "
00814 << capacityChange_ << " "; assert(stream.good());
00815 stream.write(reinterpret_cast<const char*>(poolB_),(endB_-poolB_));
00816
00817
00818
00819 }
00820 return stream;
00821 }
00822
00823 std::istream& read(std::istream& stream)
00824 {
00825 if(stream.good())
00826 {
00827 int usedMemB(0);
00828 stream >> capacity_; assert(stream.good());
00829 stream >> size_ ; assert(stream.good());
00830 stream >> capacityB_; assert(stream.good());
00831 stream >> usedMemB; assert(stream.good());
00832 stream >> uniqueID_; assert(stream.good());
00833 stream >> memoryChangeB_; assert(stream.good());
00834 stream >> capacityChange_; assert(stream.good());
00835 assert(stream.good());
00836 assert(static_cast<uTind>(usedMemB) <= capacityB_);
00837 std::cout << " capacity:" << capacity_
00838 << " size:" << size_
00839 << " usedMemB:" << usedMemB
00840 << " uniqueId:"<< uniqueID_
00841 << " memoryChangeB:" << memoryChangeB_
00842 << " capacitChange:" << capacityChange_;
00843
00844 reserve(capacity_,capacityB_,true);
00845 char tmp('E');
00846 stream.get(tmp);
00847 stream.read(reinterpret_cast<char *>(poolB_),usedMemB);
00848 endB_ +=usedMemB;
00849 rebuildHash();
00850 rebuildVts2Pos();
00851
00852
00853
00854
00855 }
00856 return stream;
00857 }
00858
00859
00860 template<class T,int T1> friend std::ostream& operator<<(std::ostream& os,const StaticPool<T,T1> & pool);
00861 template<class T,int T1> friend std::istream& operator>>(std::istream& os,const StaticPool<T,T1> & pool);
00862 };
00863
00864 template <class T,int T1>
00865 std::ostream & operator << (std::ostream & stream, const StaticPool<T, T1> & pool)
00866 {
00867 return pool.write(stream);
00868 }
00869
00870 template <class T, int T1>
00871 std::istream & operator >> (std::istream & stream, StaticPool<T, T1> & pool)
00872 {
00873 return pool.read(stream);
00874 }
00875
00876
00877
00879
00880
00882 #endif // STATICPOOL_HPP_INCLUDED