| 1 | ///\file |
|---|
| 2 | ///Named template study |
|---|
| 3 | |
|---|
| 4 | ///\e |
|---|
| 5 | |
|---|
| 6 | ///\e |
|---|
| 7 | /// |
|---|
| 8 | class AlgorithmDefaultTypes |
|---|
| 9 | { |
|---|
| 10 | public: |
|---|
| 11 | ///\e |
|---|
| 12 | |
|---|
| 13 | ///\e |
|---|
| 14 | /// |
|---|
| 15 | typedef int Adat; |
|---|
| 16 | }; |
|---|
| 17 | |
|---|
| 18 | ///\e |
|---|
| 19 | |
|---|
| 20 | ///\e |
|---|
| 21 | /// |
|---|
| 22 | template<class T = AlgorithmDefaultTypes> |
|---|
| 23 | class AlgorithmTypes : public T |
|---|
| 24 | { |
|---|
| 25 | public: |
|---|
| 26 | ///\e |
|---|
| 27 | |
|---|
| 28 | ///\e |
|---|
| 29 | /// |
|---|
| 30 | template<class X> |
|---|
| 31 | class SetAdat : public T { X Adat; }; |
|---|
| 32 | }; |
|---|
| 33 | |
|---|
| 34 | ///\e |
|---|
| 35 | |
|---|
| 36 | ///\e |
|---|
| 37 | /// |
|---|
| 38 | template<class T = AlgorithmTypes<> > |
|---|
| 39 | class AlgorithmDefaultDataFields : public T |
|---|
| 40 | { |
|---|
| 41 | protected: |
|---|
| 42 | ///\e |
|---|
| 43 | |
|---|
| 44 | ///\e |
|---|
| 45 | /// |
|---|
| 46 | typedef T TypeTraits; //Jo ez a nev? |
|---|
| 47 | protected: |
|---|
| 48 | ///\e |
|---|
| 49 | |
|---|
| 50 | ///\e |
|---|
| 51 | /// |
|---|
| 52 | typename T::Adat adat; |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | ///\e |
|---|
| 56 | |
|---|
| 57 | ///\e |
|---|
| 58 | /// |
|---|
| 59 | template<class T = AlgorithmDefaultDataFields<> > |
|---|
| 60 | class Algorithm : public T |
|---|
| 61 | { |
|---|
| 62 | int _intAdat; |
|---|
| 63 | public: |
|---|
| 64 | Algorithm() {}; |
|---|
| 65 | Algorithm(const T &tt) : T(tt) {}; |
|---|
| 66 | |
|---|
| 67 | template<class X> class _SetAdat : public T { |
|---|
| 68 | protected: |
|---|
| 69 | X adat; |
|---|
| 70 | public: |
|---|
| 71 | typedef X Adat; |
|---|
| 72 | _SetAdat() {}; //"Algorithm<>::_SetAdat<double> b;"-hez kell!!!! |
|---|
| 73 | // De az is rossz!!!!! |
|---|
| 74 | _SetAdat(const T &t,const X& x) : T(t), adat(x) {}; |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | ///\name Funtion Named Parameters |
|---|
| 78 | |
|---|
| 79 | ///@{ |
|---|
| 80 | |
|---|
| 81 | ///\e |
|---|
| 82 | |
|---|
| 83 | ///\e |
|---|
| 84 | /// |
|---|
| 85 | template<class X> |
|---|
| 86 | Algorithm<_SetAdat<X> > setAdat(const X &x) { |
|---|
| 87 | return Algorithm<_SetAdat<X> >(_SetAdat<X>(*this,x)); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | ///@} |
|---|
| 91 | ///\name Named Parameters |
|---|
| 92 | |
|---|
| 93 | ///@{ |
|---|
| 94 | |
|---|
| 95 | ///\e |
|---|
| 96 | |
|---|
| 97 | ///\e |
|---|
| 98 | /// |
|---|
| 99 | template<class X> |
|---|
| 100 | class SetAdat : |
|---|
| 101 | public Algorithm<AlgorithmDefaultDataFields< |
|---|
| 102 | typename T::TypeTraits::template SetAdat<X> > > |
|---|
| 103 | {}; |
|---|
| 104 | |
|---|
| 105 | ///@} |
|---|
| 106 | |
|---|
| 107 | ///\e |
|---|
| 108 | |
|---|
| 109 | ///\e |
|---|
| 110 | /// |
|---|
| 111 | Algorithm &setIntAdat(int i) {_intAdat=i;return *this;} |
|---|
| 112 | //vagy: |
|---|
| 113 | ///Vagy |
|---|
| 114 | |
|---|
| 115 | ///Vagy... |
|---|
| 116 | /// |
|---|
| 117 | Algorithm &intAdat(int i) {_intAdat=i;return *this;} |
|---|
| 118 | |
|---|
| 119 | //Maga az algoritmus!!!!!!! |
|---|
| 120 | ///\e |
|---|
| 121 | |
|---|
| 122 | ///\e |
|---|
| 123 | /// |
|---|
| 124 | typename T::Adat run() |
|---|
| 125 | { |
|---|
| 126 | //Itt csinalunk valamit |
|---|
| 127 | return adat; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | ~Algorithm() |
|---|
| 131 | { |
|---|
| 132 | //Itt nem csinalunk semmit |
|---|
| 133 | } |
|---|
| 134 | }; |
|---|
| 135 | |
|---|
| 136 | ///\e |
|---|
| 137 | |
|---|
| 138 | ///\e |
|---|
| 139 | /// |
|---|
| 140 | Algorithm<> algorithm() |
|---|
| 141 | { |
|---|
| 142 | return Algorithm<>(); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | int main() |
|---|
| 146 | { |
|---|
| 147 | Algorithm<> a; |
|---|
| 148 | a.run(); |
|---|
| 149 | |
|---|
| 150 | // Algorithm<>::_SetAdat<double> b; b=b;//Ez itt nem az, amit szeretnenk!!! |
|---|
| 151 | // // b.run(); |
|---|
| 152 | |
|---|
| 153 | Algorithm<>::SetAdat<double> c; //Algorithm<>::Adat<double> c; jobb vo'na |
|---|
| 154 | c.run(); |
|---|
| 155 | |
|---|
| 156 | algorithm().run(); |
|---|
| 157 | algorithm().setAdat(5.2).run(); |
|---|
| 158 | } |
|---|