alpar@1624: /*!
alpar@954:
alpar@953: \page named-param Named Parameters
alpar@953:
alpar@1624: \section named-func-param Named Function Parameters
alpar@955:
alpar@1536: C++ makes it possible to use default parameter values when calling a
alpar@1536: function. In such a case we do not have to give value for parameters,
alpar@1536: the program will use the default ones. Unfortunately sometimes this
alpar@1536: is not enough. If we do not want to give values for all the
alpar@1536: parameters, only for some of them we come across problems, because an
alpar@1536: arbitrary set of parameters cannot be omitted. On the other hand
alpar@1536: parameters have a fixed order in the head of the function. C++ can
alpar@1536: apply the default values only in the back of the order, if we do not
alpar@1536: give other value for them. So we can not give the function for
alpar@1536: example the value of the first, and the third parameter, expecting
alpar@1536: that the program will aplly the default value for the second
alpar@1536: parameter. However sometimes we would like to use some functinos
alpar@1536: exactly in this way. With a crafty trick and with some little
alpar@1536: inconvenience this is possible. We have implemented this little trick
alpar@1536: as an example below.
hegyi@1141:
hegyi@1141: \code
hegyi@1141: class named_fn
hegyi@1141: {
hegyi@1141: int _id;
hegyi@1141: double _val;
hegyi@1141: int _dim;
hegyi@1141:
hegyi@1141: public:
hegyi@1141: named_fn() : _id(0), _val(1), _dim(2) {}
hegyi@1141: named_fn& id(int p) { _id = p ; return *this; }
hegyi@1141: named_fn& val(double p) { _val = p ; return *this; }
hegyi@1141: named_fn& dim(int p) { _dim = p ; return *this; }
hegyi@1141:
hegyi@1141: run() {
hegyi@1141: printf("Here is the function itself.");
hegyi@1141: }
hegyi@1141: };
hegyi@1141: \endcode
hegyi@1141:
hegyi@1141:
hegyi@1141: The usage is the following.
hegyi@1141:
alpar@1624: We have to define a class, let's call it \c named_fn. Let us assume that
alpar@1624: we would like to use a parameter, called \c X. In the \c named_fn class we
alpar@1624: have to define an \c _X attribute, and a function \c X. The function
alpar@1624: expects a parameter with the type of \c _X, and sets the value of
alpar@1624: \c _X. After setting the value the function returns the class itself. The
alpar@1624: class also have to have a function, called for example run(), we have
alpar@1536: to implement here the original function itself. The constructor of the
alpar@1624: class have to give all the attributes like \c _X the default values of
alpar@1536: them.
hegyi@1141:
alpar@1536: If we instantiate this class, the default values will be set for the
hegyi@1619: attributes (originally the parameters), initially. If we call function
alpar@1624: \c X, we get a class with the modified parameter value of
alpar@1624: \c X. Therefore we can modify any parameter-value, independent from the
alpar@1624: order. To run the algorithm we have to call the run() function at the
alpar@1536: end of the row.
hegyi@1141:
alpar@1624: Example:
alpar@1624: \code
alpar@1624: named_fn().id(3).val(2).run();
alpar@1624: \endcode
alpar@955:
alpar@955: \section traits-classes Traits Classes
alpar@955:
alpar@1536: The procedure above can also be applied when defining classes. In this
alpar@1536: case the type of the attributes can be changed. Initially we have to
alpar@1536: define a class with the default attribute types. This is the so called
alpar@1536: Traits Class. Later on the types of these attributes can be changed,
alpar@1536: as described below. In our software \ref lemon::DijkstraDefaultTraits is an
alpar@1536: example of how a traits class looks like.
hegyi@1141:
alpar@955: \section named-templ-param Named Class Template Parameters
alpar@954:
alpar@1536: If we would like to change the type of an attribute in a class that
alpar@1536: was instantiated by using a traits class as a template parameter, and
alpar@1536: the class contains named parameters, we do not have to reinstantiate
alpar@1536: the class with new traits class. Instead of that, adaptor classes can
alpar@1536: be used like in the following cases.
hegyi@1141:
alpar@954: \code
alpar@954: Dijkstra<>::SetPredNodeMap >
alpar@954: \endcode
hegyi@1141:
alpar@954: It can also be used in conjunction with other named template
alpar@954: parameters in arbitrary order.
hegyi@1141:
alpar@954: \code
alpar@954: Dijkstra<>::SetDistMap::SetPredMap >
alpar@954: \endcode
alpar@954:
alpar@1536: The result will be an instantiated Dijkstra class, in which the
alpar@1536: DistMap and the PredMap is modified.
hegyi@1141:
alpar@1624: \section named-templ-func-param Named Function Template Parameters
alpar@955:
alpar@1536: If the class has so called wizard functions, the new class with the
alpar@1536: modified tpye of attributes can be returned by the appropriate wizard
alpar@1536: function. The usage of these wizard functions is the following:
alpar@953:
alpar@953: */