00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _InControlTmplArray_hxx_
00023 #define _InControlTmplArray_hxx_
00024
00025 #include "InControl.hxx"
00026 #include <vector>
00027
00028 namespace CLAM
00029 {
00033 template <class TProcessing>
00034 class InControlTmplArray
00035 {
00036 typedef InControlTmpl<TProcessing> TInControl;
00037 typedef typename TInControl::TPtrMemberFuncId TPtrMemberFuncId;
00038 typedef std::vector<TInControl*> Controls;
00039 Controls mControls;
00040
00041 public:
00042 InControlTmplArray(int size, const std::string &name, TProcessing* parent, TPtrMemberFuncId f);
00045 InControlTmplArray(int size, const std::list<std::string>& names, TProcessing* parent, TPtrMemberFuncId f);
00046
00047
00048 InControlTmplArray();
00049
00050 ~InControlTmplArray();
00051
00052 TInControl& operator[](int i) { return *mControls[i]; }
00053 const TInControl& operator[](int i) const { return *mControls[i]; }
00054
00055 void Resize(int size, const std::string& name, TProcessing* parent, TPtrMemberFuncId f);
00056 void Resize(int size, const std::list<std::string>& names, TProcessing* parent, TPtrMemberFuncId f);
00057
00058 int Size() const {return mControls.size();}
00059
00060 protected:
00061 void Shrink(int size);
00062
00063 };
00064
00065
00066
00067 template <class TProcessing>
00068 InControlTmplArray<TProcessing>::InControlTmplArray(
00069 int size,
00070 const std::string &name,
00071 TProcessing *parent,
00072 TPtrMemberFuncId f)
00073 {
00074 CLAM_ASSERT(parent, "InControlTmplArray must be published. Check ctr processing* parameter");
00075 Resize(size,name,parent,f);
00076 }
00077
00078 template <class TProcessing>
00079 InControlTmplArray<TProcessing>::InControlTmplArray(
00080 int size,
00081 const std::list<std::string>& names,
00082 TProcessing *parent,
00083 TPtrMemberFuncId f)
00084 {
00085 CLAM_ASSERT(parent, "InControlTmplArray must be published. Check ctr processing* parameter");
00086 Resize(size, names, parent,f);
00087 }
00088
00089 template <class TProcessing>
00090 InControlTmplArray<TProcessing>::InControlTmplArray()
00091 {
00092 mControls.resize(0);
00093 }
00094
00095 template <class TProcessing>
00096 void InControlTmplArray<TProcessing>::Resize(int size, const std::string& name, TProcessing* parent, TPtrMemberFuncId f)
00097 {
00098 int previousSize = mControls.size();
00099 if(size < previousSize)
00100 {
00101 Shrink(size);
00102 return;
00103 }
00104
00105 mControls.resize(size);
00106 for (int i = previousSize; i<size; i++) {
00107 std::stringstream str;
00108 str << name << "_" << i;
00109 mControls[i] = new TInControl(i, str.str(), parent, f);
00110 }
00111 }
00112
00113 template <class TProcessing>
00114 void InControlTmplArray<TProcessing>::Resize(int size, const std::list<std::string>& names , TProcessing* parent, TPtrMemberFuncId f)
00115 {
00116 int previousSize = mControls.size();
00117 if(size < previousSize)
00118 {
00119 Shrink(size);
00120 return;
00121 }
00122
00123 CLAM_ASSERT(size-previousSize <= names.size(), "InControlTmplArray::Resize not enoough labels are given");
00124 mControls.resize(size);
00125 std::list<std::string>::iterator name = names.begin();
00126 for (int i = previousSize; i<size; i++) {
00127 mControls[i] = new TInControl(i, *name, parent, f);
00128 }
00129 }
00130
00131 template <class TProcessing>
00132 void InControlTmplArray<TProcessing>::Shrink(int size)
00133 {
00134 int previousSize = mControls.size();
00135 CLAM_ASSERT(size < previousSize, "InControlArray::Cannot Shrink a Control Array to a larger size");
00136 for (int i = previousSize-1; i >= size; i--) {
00137 delete mControls[i];
00138 }
00139 mControls.resize(size);
00140 }
00141
00142
00143 template <class TProcessing>
00144 InControlTmplArray<TProcessing>::~InControlTmplArray()
00145 {
00146 Shrink(0);
00147 }
00148
00149 }
00150
00151 #endif
00152