メインページ | ネームスペース一覧 | クラス階層 | 構成 | Directories | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ | 関連ページ

Combination.h

説明を見る。
00001 #ifndef BASE_COMBINATION_H
00002 #define BASE_COMBINATION_H
00003 #include "Env.h"
00004 #include <list>
00005 #include <set>
00006 
00007 /** @file Combination.h キーワード検索機能つきリストの定義*/
00008 namespace Spr {;
00009 
00010 /** 組み合わせ配列(入れ替え不可,4角形になる)*/
00011 template <class T>
00012 class UTCombination:public std::vector<T>{
00013     int height_;
00014     int width_;
00015 public:
00016     typedef std::vector<T> base_type;
00017     UTCombination(){ height_ = 0; width_ = 0; }
00018     /// サイズの設定    
00019     void resize(int h, int w){
00020         if (h*w > height_*width_){  //  大きくなるなら,先にリサイズ
00021             base_type::resize(h * w);
00022         }
00023         iterator b = begin();
00024         if (h < height_){   //  使わなくなった行をクリア
00025             for(int l=h; l<height_; ++l){
00026                 for(int x=0; x<width_; ++x) b[width_*l+x] = T();
00027             }
00028         }
00029         if (w > width_){    //  幅が増える場合,後ろから移動
00030             for(int l=height_-1; l>=0; --l){
00031                 for(int x=w; x > width_-1; --x) b[w*l+x]=T();
00032                 for(int x=width_-1; x>=0; --x) b[w*l+x] = b[width_*l+x];
00033             }
00034         }else if (w < width_){  //  幅が減る場合,前から移動
00035             for(int l=1; l<height_; ++l){
00036                 for(int x=0; x<width_; ++x) b[w*l+x] = b[width_*l+x];
00037             }
00038         }
00039         if (h*w > height_*width_){  //  小さくなるなら最後にリサイズ
00040             base_type::resize(h * w);
00041         }
00042         height_ = h;
00043         width_ = w;
00044     }
00045     int height(){ return height_; };
00046     int width(){ return width_; };
00047     T& item(int i, int j){
00048         assert(i < height());
00049         assert(j < width());
00050         return begin()[i*width() + j];
00051     }
00052     void clear(){
00053         base_type::clear();
00054         height_ = 0;
00055         width_ = 0;
00056     }
00057     const T& item(int i, int j) const { return ((UTCombination<T>*)this)->item(i,j); }
00058 //  T& operator [] (int i, int j){ item(i,j); }
00059 //  const T& operator [] (int i, int j) const { item(i,j); }
00060 };
00061 
00062 }
00063 
00064 #endif

Springheadに対してSun Apr 16 01:57:49 2006に生成されました。  doxygen 1.4.1