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