Console: More documentation and cleanup
[senf.git] / Console / Traits.hh
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Traits public header */
25
26 #ifndef HH_Traits_
27 #define HH_Traits_ 1
28
29 // Custom includes
30 #include <iostream>
31 #include <boost/intrusive_ptr.hpp>
32 #include "../Utils/intrusive_refcount.hh"
33 #include "Parse.hh"
34 #include "Node.hh"
35
36 //#include "Traits.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40 namespace console {
41
42     /** \brief Customize return value formating
43
44         ReturnValueTraits provides return value formatting. The default implementation provided here
45         will just write the value to the output stream. 
46
47         To customize this behavior for some type, specialize this class for the type.
48
49         The output should \e not end in a newline since one is added automatically.
50      */
51     template <class Type>
52     struct ReturnValueTraits
53     {
54         typedef Type type;
55
56         static void format(Type const & value, std::ostream & os);
57                                         ///< Write \a value to \a os
58     };
59
60     /** \brief Customize argument parsing
61         
62         ArgumentTraits provides argument parsing, Additionally, this class provides a way to get a
63         string-description of a type and to convert a value back into it's string representation
64         used to display default values.
65         
66         The default implementation provided here will use \c boost::lexical_cast and thereby \c
67         iostreams to convert an argument consisting of a single input token into the required
68         type. Types are named by returning the last component of the fully scoped name (e.g. \c
69         "string" for \c std::string). Values are formatted again using \c boost::lexical_cast.
70
71         To customize this behavior for some type, specialize this class for the type.
72      */
73     template <class Type>
74     struct ArgumentTraits
75     {
76         typedef Type type;
77
78         static void parse(ParseCommandInfo::TokensRange const & tokens, Type & out);
79                                         ///< Parse token range into value
80                                         /**< This function needs to parse \a tokens and write the
81                                              parsed value into \a out. This function needs to parse
82                                              the \e complete list of tokens, additional tokens must
83                                              be considered as syntax error.
84                                              \throws SyntaxErrorException
85                                              \param[in] tokens tokens to parse
86                                              \param[out] out parsed value */
87
88         static std::string description(); ///< String description of type
89                                         /**< Returns the string description of \a Type. Used to
90                                              generate online help. */
91         static std::string str(Type const & value); ///< Stringify value
92                                         /**< To show default values in the online help, this
93                                              function converts a value back into a one-line string
94                                              representation. */
95     };
96     
97 }}
98
99 ///////////////////////////////hh.e////////////////////////////////////////
100 //#include "Traits.cci"
101 //#include "Traits.ct"
102 #include "Traits.cti"
103 #endif
104
105 \f
106 // Local Variables:
107 // mode: c++
108 // fill-column: 100
109 // comment-column: 40
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"
114 // End: