SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送
メインページ   名前空間一覧   クラス階層   構成   ファイル一覧   名前空間メンバ   構成メンバ   ファイルメンバ  

dKingyoDataWrapper.h

解説を見る。
00001 
00002 
00003  
00004 #ifndef dKingyoDataWrapper_H_
00005 #define dKingyoDataWrapper_H_
00006 
00007 
00008 #include "dKingyoMemoryManager.h"
00009 #include "dKingyoArrayManager.h"
00010 
00011 
00012 namespace dkutil{//begin dkutil
00013 namespace memory{//begin memory
00014 
00015 /*
00016 http://wwwinfo.cern.ch/asd/lhc++/ObjectSpace/doc/2.1/stdusr/1stclass.8.html
00017 から拾ってきたもの。説明が非常にためになりました。ありがとうございます。
00018 #include <iostream>
00019 #include <functional>
00020 #include <ospace/stl/hashmap.h>
00021 
00022 typedef hash_map< char, int, hash<char>, equal_to<char> > map_type;
00023 
00024 void
00025 main()
00026   {
00027   map_type m;
00028 
00029   // Store mappings between roman numerals and decimals.
00030   m[ 'l' ] = 50;
00031   m[ 'x' ] = 20; // Deliberate mistake.
00032   m[ 'v' ] = 5;
00033   m[ 'i' ] = 1;
00034   cout << "m[ 'x' ] = " << m[ 'x' ] << "\n";
00035 
00036   m[ 'x' ] = 10; // Correct mistake.
00037   cout << "m[ 'x' ] = " << m[ 'x' ] << "\n";
00038 
00039   // Note default value ( 0 ) is added.
00040   cout << "m[ 'z' ] = " << m[ 'z' ] << "\n";
00041   cout << "m.count( 'z' ) = " << m.count( 'z' ) << "\n";
00042 
00043   pair< map_type::iterator, bool > p;
00044   p = m.insert( pair< char, int >( char, int )( 'c', 100 ) );
00045   if ( p.second )
00046     cout << "First insertion successful\n";
00047 
00048   p = m.insert( pair< char, int >( char, int )( 'c', 100 ) );
00049   if ( p.second )
00050     cout << "Second insertion successful\n";
00051   else
00052     cout
00053       << "Existing pair "
00054       << ( *( p.first ) ).first
00055       << " -> "
00056       << ( *( p.first ) ).second
00057       << "\n";
00058   }
00059 */
00060 
00061 
00070 
00071 template<class K,class V>//V = value K = key
00072 class dKingyoDataWrapperSTLPortHashMap : public IdKingyoDataWrapper<V,K>{
00073 protected:
00074     typedef DKUTIL_HASHMAP<K,V> hashmap;
00075     hashmap m;//map
00076     typedef hashmap::iterator hash_map_it;
00077     typedef std::pair<hash_map_it,bool> hash_map_result;
00078     typedef std::pair<K,V> hash_map_data;
00079 public:
00080     dKingyoDataWrapperSTLPortHashMap(){}
00081     virtual ~dKingyoDataWrapperSTLPortHashMap(){}
00087 
00088     virtual V GetData(K key){
00089         hash_map_it it = m.find(key);
00090         if(it==m.end()){
00091             throw -1;//だめだめよ!
00092         }
00093         return (*it).second;
00094     }
00100 
00101     virtual bool SetData(K key,V value){
00102         hash_map_result result;
00103         hash_map_data data(key,value);
00104         result=m.insert(data);
00105         //if(result.second==true){
00106         //  (*result.first).first=key;
00107         //}//ぐわあああああああhash_mapが分からない!!!
00108         return result.second;
00109     }
00115 
00116     virtual bool DeleteDataByKey(K key){
00117         m.erase(key);//何が帰るか良く分からない(泣 だれかおしえて〜な
00118         return true;
00119     }
00124 
00125     virtual bool DeleteDataByValue(V value){
00126         hash_map_it it=m.begin();
00127         while(it!=m.end()){
00128             if(value==(*it).second){
00129                 m.erase(it);//これでいいんかいな!?だれかhash_mapの関数リファレンスおしえてーな
00130                 return true;
00131             }
00132             it++;
00133         }
00134         return false;
00135     }
00136 
00137 };
00138 
00139 
00140 template<class K,class V>//V = value K = key
00141 class dKingyoDataWrapperMap : public IdKingyoDataWrapper<V,K>{
00142 protected:
00143     std::map<K,V> m;//map
00144     typedef std::map<K,V>::iterator map_it;
00145     typedef std::pair<map_it,bool> map_result;
00146     typedef std::pair<K,V> map_data;
00147 public:
00148     dKingyoDataWrapperMap(){}
00149     virtual ~dKingyoDataWrapperMap(){}
00155 
00156     virtual V GetData(K key){
00157         map_it it = m.find(key);
00158         if(it==m.end())
00159             throw -1;//だめだめよ!
00160         return m[(*it).first];
00161         //for ( iter = mapSS.begin( ); iter != mapSS.end( ); iter++ ) {
00162             //cout << iter->first << " : " << mapSS[iter->first] << endl;
00163         //}
00164     }
00170 
00171     virtual bool SetData(K key,V value){
00172         map_result result;
00173         map_data data(key,value);
00174         result=m.insert(data);
00175         return result.second;
00176     }
00182 
00183     virtual bool DeleteDataByKey(K key){
00184         m.erase(key);//何が帰るか良く分からない(泣 だれかおしえて〜な
00185         return true;
00186     }
00191 
00192     virtual bool DeleteDataByValue(V value){
00193         map_it it=m.begin();
00194         while(it!=m.end()){
00195             if(value==m[(*it).first]){
00196                 m.erase(it);//これでいいんかいな!?だれかhash_mapの関数リファレンスおしえてーな
00197                 return true;
00198             }
00199             it++;
00200         }
00201         return false;
00202     }
00203 };      
00204 
00206 template<class K,class V>//V = value K = key 
00207 class dKingyoDataWrapperOverwriteAcceptMap : public dKingyoDataWrapperMap<K,V>{
00208 public:
00209     virtual bool SetData(K key,V value){
00210         map_result result;
00211         map_data data(key,value);
00212         result=m.insert(data);
00213         if(result.second==false){
00214             m[key]=value;
00215             throw DKINGYO_DATA_WRAPPER_OVERWRITE;//投げます^^;
00216         }
00217         return true;//常にTRUEしかないでしょう^^;
00218     }
00219 };
00220 
00221 
00227 
00228 template<class V>
00229 class dKingyoDataWrapperArrayWarehouse : public IdKingyoDataWrapper<V,DWORD *>{
00230 protected:
00231     dkutil::memory::dKingyoArrayOneByOneDynamic<V> m;
00232 public:
00233     dKingyoDataWrapperArrayWarehouse(){}
00234     virtual ~dKingyoDataWrapperArrayWarehouse(){}
00235     virtual V GetData(DWORD *setkey){
00236 //#ifdef _DEBUG
00237         if(m.DataMax()<=(*setkey))//what are you doing abou!!! マックスよりキーがでかいとエラー
00238             return NULL;
00239 //#endif
00240         return m.Data()[(*setkey)];
00241     }
00242     virtual bool SetData(DWORD *getkey,V value){
00243         V *temp=m.GetArray(getkey);
00244         if(temp==NULL)
00245             return false;
00246         *temp=value;//ぶち込む
00247         
00248         return true;
00249     }
00250     virtual bool DeleteDataByKey(DWORD *setkey){
00251         m.ReleaseArray(setkey);
00252         return true;//常にTRUEってのはなぁ^^;
00253     }
00254     virtual bool DeleteDataByValue(V value){
00255         DWORD max=m.DataMax();
00256         V *a=m.Data();
00257         bool r=false;
00258         for(DWORD i=0;i<max;i++){//線型?線形探索かよ〜〜 めんど〜〜 O(N)ってなんなのよ〜〜遅すぎ!
00259             if(a[i]==value){//同じ奴を見つけた!!
00260                 m.ReleaseArray(&i);//すごく邪道な開放の仕方^^;
00261                 r=true;
00262                 break;
00263             }
00264         }
00265         return r;
00266     }
00267 };
00268 
00269         
00270 
00271 /*
00272 class dKingyoDataWrapperBoostPropertyMap{
00273 protected:
00274     boost::
00275 }
00276 */
00277 
00278 
00279 
00280 #ifdef USE_DKINGYO_OBJECT_TEST
00281 
00282 extern void dKingyoDataWrapperMapTest();
00283 extern void dKingyoDataWrapperHashMapExpectionTest();
00284 
00285 #endif //end of USE_DKINGYO_OBJECT_TEST
00286 
00287 
00288 
00289 }//end of memory
00290 }//end of dkutil
00291 
00292 #endif // end of once include
00293 

dKingyoUtilClass (dkutil)に対してMon Jun 9 01:32:40 2003に生成されました。 doxygen1.3