00001 #ifndef BASE_COMBINATION_H
00002 #define BASE_COMBINATION_H
00003 #include "Env.h"
00004 #include <list>
00005 #include <set>
00006
00007
00008 namespace Spr {;
00009
00010
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
00059
00060 };
00061
00062 }
00063
00064 #endif