00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef VALUE_HOLDER_H
00028 #define VALUE_HOLDER_H
00029
00030 #include <ost/base.hh>
00031 #include <ost/img/module_config.hh>
00032 #include <ost/img/data_types.hh>
00033 #include <ost/img/size.hh>
00034
00035 #include "type_fw.hh"
00036
00037 namespace value_holder_test {
00038
00039 template <typename V>
00040 void ReleaseAndReconstruct();
00041
00042 }
00043
00044 namespace ost { namespace img { namespace image_state {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 template <typename V>
00057 class TEMPLATE_EXPORT ValueHolder {
00058 public:
00059 typedef V* VPtr;
00060 typedef VPtr* VPtrPtr;
00061
00065
00066 ValueHolder(unsigned int wi, unsigned int he, unsigned int de);
00067
00069 ValueHolder(const Size& s);
00070
00072 ValueHolder(const Size& s, const Size& ps);
00073
00075 ValueHolder(const ValueHolder<V>& h);
00076
00078 template <typename U>
00079 ValueHolder(const Size& s, ValueHolder<U>& v):
00080 width_(s[0]),
00081 height_(s[1]),
00082 depth_(s[2]),
00083 volume_(width_*height_*depth_),
00084 volume2_(v.GetPhysicalSize()*sizeof(U)/sizeof(V)),
00085 data_(reinterpret_cast<V*>(v.ReleaseData())),
00086 row_(0),
00087 slice_(0)
00088 {
00089 try {
00090 setup();
00091 } catch(...) {
00092 delete []data_;
00093 }
00094 }
00095
00096
00098
00103 ValueHolder& operator=(const ValueHolder<V>& h);
00104
00106 ~ValueHolder();
00107
00109
00115 VPtr ReleaseData();
00116
00118 void Swap(ValueHolder& vh);
00120
00122
00123
00124
00125 unsigned int GetWidth() const {return width_;}
00126
00127 unsigned int GetHeight() const {return height_;}
00128
00129 unsigned int GetDepth() const {return depth_;}
00130
00131 unsigned int GetVolume() const {return volume_;}
00132
00133 Size GetSize() const;
00134
00135 static DataType GetDataType();
00136
00137 unsigned int GetPhysicalSize() const {return volume2_;}
00138
00139 long MemSize() const;
00140
00142
00149
00150
00154 V& Value(const Index& i);
00155
00157
00161 const V& Value(const Index& i) const;
00162
00164
00167 V& Value(unsigned int i);
00168
00170
00173 const V& Value(unsigned int i) const;
00174
00175
00177 VPtr GetData() {return data_;}
00179 const VPtr GetData() const {return data_;}
00180
00182 int DataCount() const {return volume_;}
00183
00185
00188 int GetDataCount() const {return volume_;}
00189
00190 const VPtr GetEnd() const {return &data_[volume_];}
00191
00193 VPtr* GetRows() {return row_;}
00195 const VPtr* GetRows() const {return row_;}
00197
00200 int GetRowCount() const {return width_*height_;}
00201
00203 VPtrPtr* GetSlices() {return slice_;}
00205 const VPtrPtr* GetSlices() const {return slice_;}
00207
00210 int GetSliceCount() const {return width_;}
00211
00213 private:
00214 unsigned int width_, height_, depth_, volume_;
00215
00216 unsigned int volume2_;
00217
00218
00219 V* data_;
00220
00221 V** row_;
00222
00223 V*** slice_;
00224
00225 void setup();
00226 void clear();
00227 };
00228
00229 }}}
00230
00231 #endif