SourceForge.jp

container.h

説明を見る。
00001 
00002 
00010 #ifndef dkutil_container__
00011 #define dkutil_container__
00012 
00013 #include "array_onebyone.h"
00014 
00015 namespace dkutil{
00016 //**********************************************************
00017 //構造 
00018 //メモリの領域 構造
00019 //SIZE分の配列をコンテナとする。
00020 //*は配列の1つの要素だと思ってください。
00021 // 1 *********************
00022 // 2 *********************
00023 // 3 *********************
00024 // ・ *********************
00025 // ・ *********************
00026 // ・ *********************
00027 // UINT_MAX *********************
00028 
00029 //この中から開いている1つの要素を探し出して その中に代入するというものです。
00030 //もちろん UINT_MAXまで配列を作成するわけではありません。必要に応じて追加していきます。
00031 //最大UINT_MAXまでの配列を作ることができます。
00032 //最大 SIZE * UINT_MAX までの要素を管理できると思います。
00033 
00034 //改造の余地
00035 //・CONTAINER自体に空きが出てきた場合、計算して二つのコンテナを一つにまとめる処理とか。
00036 //・STLのlistのiteratorは12byte と超重い・・・ 自作listを作る予定・・・
00037 
00038 
00039 //**********************************************************
00040 
00041 template<class T,unsigned int SIZE=enuDefaultExtendSize,typename A=std::allocator<T>,
00042     class CONTAINER= array_onebyone_ex<T,A,std::vector<T,A> ,std::deque<T,A> ,SIZE>,
00043     class CHAIN=std::list<CONTAINER,A> 
00044 >
00045 class container{
00046 public:
00047     enum{
00048         enuExtendNum = SIZE,
00049     };
00050     typedef CONTAINER CONTAINER_TYPE;
00051     typedef CHAIN LIST_TYPE;
00052     typedef CONTAINER::DEQUE_TYPE DEQUE_TYPE;
00053     typedef CONTAINER::VECTOR_TYPE VECTOR_TYPE;
00054     
00055 
00056     typedef struct tugHandle{
00057         LIST_TYPE::iterator it;//iterator
00058         CONTAINER_TYPE::handle h;//handle
00059         T &operator *(){return (*it).at(h);}
00060         //T *operator ->(){return (*it).at_ptr(h);}
00061     }handle;
00062 
00063 
00064     explicit container(){
00065         m_c.clear();
00066         m_now_it = new_it();
00067         //dOutputDebugString("it size = %d\n",sizeof(iterator));
00068     }
00069     virtual ~container(){   m_c.clear();}
00072     handle push(const T &x)
00073     {
00074         if((*m_now_it).size() >= enuExtendNum && (*m_now_it).empty_free_queue())
00075         {//すでに今使っているコンテナに空き領域がなくなっていたら
00076             m_now_it = sarch_free_container();
00077             if(m_now_it == m_c.end())
00078             {//さらにすでに確保済みの空き領域もなくなっていたら
00079                 //新しい領域作るしかないでしょう・・・
00080                 m_now_it = new_it();
00081             }
00082             else
00083             {//いや、他のコンテナに空き領域はある。
00084             }
00085         }
00086         
00087         handle hand;
00088         hand.h = (*m_now_it).push(x);//ハンドルを保存する
00089         hand.it = m_now_it;//今のイテレータ
00090 
00091         return tit;
00092     }
00093     void pop(const handle &get_it){
00094         (*(get_it.it)).pop(get_it.h);
00095     }
00096     T &reference_item(const handle &ref){
00097         return (*ref);
00098     }
00099 
00100 protected:
00101     LIST_TYPE::iterator new_it(){
00102         m_c.push_back(CONTAINER_TYPE());
00103         LIST_TYPE::iterator it=boost::prior(m_c.end());
00104         //for(int c=0;c != m_c.size() - 1;it++,c++){}
00105         //if((*it) != m_c.back()){MB("ERROR");}
00106         return it;
00107     }
00108     bool all_empty_container(){
00109         LIST_TYPE::iterator it=m_c.begin();
00110         for(int count=0;it != m_c.end();it++){
00111             if((*it).empty_free_queue()){
00112                 count++;
00113             }
00114         }
00115         return (count==m_c.size());// == true or false??
00116     }
00117     LIST_TYPE::iterator sarch_free_container(){
00118         for(LIST_TYPE::iterator it=m_c.begin();it != m_c.end();it++){
00119             if(!(*it).empty_free_queue()){
00120                 return it;
00121             }
00122         }
00123         return m_c.end();
00124     }
00125         
00126     LIST_TYPE::iterator m_now_it;//member of container list now pointing iterator
00127 
00128     LIST_TYPE m_c;//member of container list
00129 };
00130 
00131 
00132 
00133 
00134 }//end of dkutil
00135 
00136 
00137 
00138 #endif//end of dkutil_container__

dkutil 1.02リリース前 d金魚専用マニュアルバージョンに対してSun Dec 28 21:23:07 2003に生成されました。 doxygen 1.3.5