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