]> Creatis software - clitk.git/blob - cmake/gengetopt/gm_utils.h
Added FindGengetopt.cmake which compiles gengetopt if not installed.
[clitk.git] / cmake / gengetopt / gm_utils.h
1 //
2 // C++ Interface: gm_utils
3 //
4 // Description:
5 //
6 //
7 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #ifndef GM_UTILS_H
14 #define GM_UTILS_H
15
16 #include <string>
17 #include <iostream>
18
19 #include "ggos.h"
20
21 using std::string;
22
23 /**
24  * @param name
25  * @return a copy of the string passed after canonizing it (i.e. '-' and
26  * '.' are transformed in '_').
27  */
28 char *canonize_names(const char * name);
29
30 /**
31  * @param name
32  * @return a copy of the string passed after canonizing it (i.e. '-' and
33  * '.' are transformed in '_').
34  */
35 const string canonize_name(const string &name);
36
37 /**
38  * @param s the string representing an enum value
39  * @return a copy of the string passed after canonizing it (i.e. '-' and
40  * becomes _MINUS_, '+' becomes _PLUS_)
41  */
42 const string canonize_enum(const string &s);
43
44 const string strip_path(const string &);
45 const string to_upper(const string &);
46
47 /**
48  * All multiple options are of type string
49  * @return All multiple options are of type string
50  */
51 bool has_multiple_options_all_string();
52
53 /**
54  * Has multiple options and at least one is of type string
55  * @return Has multiple options and at least one is of type string
56  */
57 bool has_multiple_options_string();
58
59 /**
60  * Has multiple options and at least one has a default value
61  * @return Has multiple options and at least one has a default value
62  */
63 bool has_multiple_options_with_default();
64
65 bool has_multiple_options();
66 bool has_multiple_options_with_type();
67 bool has_required();
68 bool has_dependencies();
69 bool has_options_with_type();
70 bool has_options_with_mode();
71 bool has_options();
72 bool has_hidden_options();
73 bool has_options_with_details();
74 bool has_values();
75
76 /**
77  * Whether the specified option deals with number
78  *
79  * @param opt
80  * @return
81  */
82 bool is_numeric(const gengetopt_option *opt);
83
84 /**
85  * Performs word wrapping on the passed string (and return the result in the first
86  * parameter).
87  *
88  * @param wrapped the output parameter
89  * @param from_column the string start from this column
90  * @param second_indent an additional indentation for lines after the
91  * first one
92  * @param orig the original string that must be wrapped
93  */
94 void wrap_cstr (string &wrapped, unsigned int from_column, unsigned int second_indent, const string &orig);
95
96 /**
97  * Searches for characters which are not newlines.
98  *
99  * @param buf where to search for new characters
100  * @param num_of_newlines where the number of newlines
101  * before the first non newline char will be stored
102  * @return the position in the string after the (possible) new line char
103  */
104 int not_newlines(const string &buf, int &num_of_newlines);
105
106 /**
107  * Function object to print something into a stream (to be used with for_each)
108  */
109 template<class T>
110 struct print_f : public std::unary_function<T, void>
111 {
112     print_f(std::ostream& out, const string &s = ", ") : os(out), sep(s) {}
113     void operator() (T x) { os << x << sep; }
114     std::ostream& os;
115     const string &sep;
116 };
117
118 /**
119  * Function object to print a pair into two streams (to be used with for_each)
120  */
121 template<class T>
122 struct pair_print_f : public std::unary_function<T, void>
123 {
124     pair_print_f(std::ostream& out1, std::ostream& out2, const string &s = ", ") :
125         os1(out1), os2(out2), sep(s) {}
126     void operator() (T x) { os1 << x.first << sep; os2 << x.second << sep;}
127     std::ostream &os1, &os2;
128     const string &sep;
129 };
130
131 #endif