00001 /* probTable.h 00002 */ 00003 #ifndef _PROBTABLE_H 00004 #define _PROBTABLE_H 00005 00006 #include "osl/misc/carray.h" 00007 namespace osl 00008 { 00009 namespace category 00010 { 00014 template <int IndexMax> 00015 class ProbTable 00016 { 00017 protected: 00018 CArray<int,IndexMax> prob; 00019 int min; 00020 CArray<char,128> filename; 00021 public: 00022 ProbTable(); 00023 virtual ~ProbTable(); 00024 ProbTable(const char *home, const char *name); 00025 void init(const char *filename); 00026 int operator[](int i) const 00027 { 00028 assert(initialized()); 00029 assert(i < IndexMax); 00030 return prob[i]; 00031 } 00032 int minProb() const { return min; } 00034 virtual void interpolate(); 00035 bool initialized() const { return filename[0]; } 00036 static size_t indexMax() { return IndexMax; } 00038 static int roundUp(int val) { return val; /*(val + 31) & (~31);*/ } 00039 }; 00040 00044 struct FixedValueTable : public ProbTable<1> 00045 { 00046 typedef ProbTable<1> base_t; 00047 FixedValueTable(const char *home, const char *name); 00048 FixedValueTable(size_t val); 00049 }; 00050 00051 const size_t PieceValueTableLength = 86; 00055 struct PieceValueTable : public ProbTable<PieceValueTableLength> 00056 { 00057 typedef ProbTable<PieceValueTableLength> base_t; 00058 PieceValueTable(const char *home, const char *name); 00059 ~PieceValueTable(); 00060 00061 void interpolate(); 00062 enum { RANGE = 2750 }; 00067 static int getIndex(int diff) 00068 { 00069 if (diff >= RANGE) 00070 return indexMax()-1; 00071 diff += RANGE; 00072 if (diff < 0) 00073 return 0; 00074 return diff >> 6; 00075 } 00076 }; 00077 00078 template <class ProbTable> 00079 struct Interpolator : public ProbTable 00080 { 00081 Interpolator(const char *home, const char *name); 00082 }; 00083 } // namespace category 00084 } // namespace osl 00085 00086 template <class ProbTable> 00087 osl::category:: 00088 Interpolator<ProbTable>::Interpolator(const char *home, const char *name) 00089 : ProbTable(home, name) 00090 { 00091 ProbTable::interpolate(); 00092 } 00093 00094 #endif /* _PROBTABLE_H */ 00095 // ;;; Local Variables: 00096 // ;;; mode:c++ 00097 // ;;; c-basic-offset:2 00098 // ;;; End: