IMP  2.3.1
The Integrative Modeling Platform
flags.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/flags.h
3  * \brief Various general useful macros for IMP.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPBASE_FLAGS_H
10 #define IMPBASE_FLAGS_H
11 
12 #include <IMP/base/base_config.h>
13 #include <boost/cstdint.hpp>
14 #include "types.h"
15 #include <string>
16 
17 IMPBASE_BEGIN_NAMESPACE
18 /** \name Flags
19 
20  These methods add support for shared command
21  line flags to \imp. Programs that use this have access to flags
22  declared in modules which allow users to do things like control
23  log level and turn on and off profiling to see what is going on.
24  These functions are Python accessible.
25 
26  In C++, you can also use the AddFloatFlag, AddStringFlag,
27  AddBoolFlag and AddIntFlag classes to add flags statically. @{
28 */
29 //! Return the name of the current executable.
30 IMPBASEEXPORT std::string get_executable_name();
31 
32 #ifndef SWIG
33 //! Parse the command line flags and return the positional arguments.
34 /**
35  \param[in] argc argc
36  \param[in] argv argv
37  \param[in] description A message describing what the program does.
38  */
39 IMPBASEEXPORT void setup_from_argv(int argc, char **argv,
40  std::string description);
41 
42 /** Parse the command line flags and return the
43  positional arguments returning unknown flags in a list. Use this version
44  if some arguments are to be parsed by a different system.
45 
46  \param[in] argc argc
47  \param[in] argv argv
48  \param[in] description A message describing what the program does.
49  */
50 IMPBASEEXPORT Strings setup_from_argv_allowing_unknown(int argc, char **argv,
51  std::string description);
52 
53 /** Parse the command line flags and return the
54  positional arguments.
55 
56  \param[in] argc argc
57  \param[in] argv argv
58  \param[in] description A message describing what the program does.
59  \param[in] positional_description A message describing the the
60  positional arguments
61  \param[in] num_positional A positive integer to require that
62  many positional arguments, or a negative integer to require at
63  least that many.
64  */
65 IMPBASEEXPORT Strings
66  setup_from_argv(int argc, char **argv, std::string description,
67  std::string positional_description, int num_positional);
68 #endif
69 
70 /** Parse the command line flags and return the
71  positional arguments. For Python.
72 
73  \param[in] argv sys.argv
74  \param[in] description A message describing what the program does.
75  */
76 IMPBASEEXPORT void setup_from_argv(const Strings &argv,
77  std::string description);
78 
79 /** Parse the command line flags and return the
80  positional arguments. For Python.
81 
82  \param[in] argv sys.argv
83  \param[in] description A message describing what the program does.
84  \param[in] positional_description A message describing the positional
85  arguments, eg "input.pdb output.pdb"
86  \param[in] num_positional A positive integer to require that
87  many positional arguments, or a negative integer to require at
88  least that many.
89  */
90 IMPBASEEXPORT Strings
91  setup_from_argv(const Strings &argv, std::string description,
92  std::string positional_description, int num_positional);
93 
94 #ifndef SWIG
95 /** Define one of these in C++ to add a new int flag storing
96  into the passed variable.
97 
98  \note You should consider using Flag<std::string> instead.
99 */
100 struct IMPBASEEXPORT AddStringFlag {
101  AddStringFlag(std::string name, std::string description,
102  std::string *storage);
103 };
104 #endif
105 
106 /** For Python use.*/
107 IMPBASEEXPORT void add_string_flag(std::string name, std::string default_value,
108  std::string description);
109 /** For Python use.*/
110 IMPBASEEXPORT std::string get_string_flag(std::string name);
111 
112 #ifndef SWIG
113 /** Define one of these in C++ to add a new boost::int64_t flag storing
114  into the passed variable.
115 
116  \note You should consider using Flag<boost::int64_t> instead.
117 */
118 struct IMPBASEEXPORT AddIntFlag {
119  AddIntFlag(std::string name, std::string description,
120  boost::int64_t *storage);
121 };
122 #endif
123 
124 /** For Python use.*/
125 IMPBASEEXPORT void add_int_flag(std::string name, size_t default_value,
126  std::string description);
127 /** For Python use.*/
128 IMPBASEEXPORT size_t get_int_flag(std::string name);
129 
130 #ifndef SWIG
131 /** Define one of these in C++ to add a new bool flag storing
132  into the passed variable.
133 
134  \note You should consider using Flag<bool> instead.
135 */
136 struct IMPBASEEXPORT AddBoolFlag {
137  AddBoolFlag(std::string name, std::string description, bool *storage);
138 };
139 #endif
140 
141 /** For Python use. Default is always false.*/
142 IMPBASEEXPORT void add_bool_flag(std::string name, std::string description);
143 /** For Python use.*/
144 IMPBASEEXPORT bool get_bool_flag(std::string name);
145 
146 #ifndef SWIG
147 /** Define one of these in C++ to add a new float flag storing
148  into the passed variable.
149 
150  \note You should consider using Flag<double> instead.
151 */
152 struct IMPBASEEXPORT AddFloatFlag {
153  AddFloatFlag(std::string name, std::string description, double *storage);
154 };
155 #endif
156 
157 /** For Python use.*/
158 IMPBASEEXPORT void add_float_flag(std::string name, double default_value,
159  std::string description);
160 /** For Python use.*/
161 IMPBASEEXPORT double get_float_flag(std::string name);
162 /** @} */
163 
164 /** Prints out the help message, useful if you have extra error checking
165  and the flags don't pass it.*/
166 IMPBASEEXPORT void write_help(std::ostream &out = std::cerr);
167 
168 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
169 /* Exposing global variables through swig is kind of broken,
170  see issue #723. */
171 extern IMPBASEEXPORT AdvancedFlag<bool> run_quick_test;
172 #endif
173 // defined in static.cpp
174 
175 /** Executables can inspect this flag and when it is true, run a shorter,
176  simpler version of their code to just make sure things work.
177 */
178 inline bool get_is_quick_test() { return run_quick_test; }
179 
180 IMPBASE_END_NAMESPACE
181 
182 #endif /* IMPBASE_FLAGS_H */
bool get_is_quick_test()
Definition: flags.h:178
Basic types used by IMP.
size_t get_int_flag(std::string name)
double get_float_flag(std::string name)
void add_float_flag(std::string name, double default_value, std::string description)
bool get_bool_flag(std::string name)
IMP::base::Vector< String > Strings
Standard way to pass a bunch of String values.
Definition: types.h:51
std::string get_string_flag(std::string name)
void add_bool_flag(std::string name, std::string description)
void add_string_flag(std::string name, std::string default_value, std::string description)
Use this to add an advanced flag to the program.
Definition: Flag.h:53
void write_help(std::ostream &out=std::cerr)
void add_int_flag(std::string name, size_t default_value, std::string description)
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Strings setup_from_argv_allowing_unknown(int argc, char **argv, std::string description)
std::string get_executable_name()
Return the name of the current executable.