IMP  2.2.1
The Integrative Modeling Platform
base/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
34  positional arguments.
35 
36  \param[in] argc argc
37  \param[in] argv argv
38  \param[in] description A message describing what the program does.
39  */
40 IMPBASEEXPORT void setup_from_argv(int argc, char **argv,
41  std::string description);
42 
43 /** Parse the command line flags and return the
44  positional arguments returning unknown flags in a list. Use this version
45  if some arguments are to be parsed by a different system.
46 
47  \param[in] argc argc
48  \param[in] argv argv
49  \param[in] description A message describing what the program does.
50  */
51 IMPBASEEXPORT Strings setup_from_argv_allowing_unknown(int argc, char **argv,
52  std::string description);
53 
54 /** Parse the command line flags and return the
55  positional arguments.
56 
57  \param[in] argc argc
58  \param[in] argv argv
59  \param[in] description A message describing what the program does.
60  \param[in] positional_description A message describing the the
61  positional arguments
62  \param[in] num_positional A positive integer to require that
63  many positional arguments, or a negative integer to require at
64  least that many.
65  */
66 IMPBASEEXPORT Strings
67  setup_from_argv(int argc, char **argv, std::string description,
68  std::string positional_description, int num_positional);
69 #endif
70 
71 /** Parse the command line flags and return the
72  positional arguments. For python.
73 
74  \param[in] argv sys.argv
75  \param[in] description A message describing what the program does.
76  */
77 IMPBASEEXPORT void setup_from_argv(const Strings &argv,
78  std::string description);
79 
80 /** Parse the command line flags and return the
81  positional arguments. For python.
82 
83  \param[in] argv sys.argv
84  \param[in] description A message describing what the program does.
85  \param[in] positional_description A message describing the positional
86  arguments, eg "input.pdb output.pdb"
87  \param[in] num_positional A positive integer to require that
88  many positional arguments, or a negative integer to require at
89  least that many.
90  */
91 IMPBASEEXPORT Strings
92  setup_from_argv(const Strings &argv, std::string description,
93  std::string positional_description, int num_positional);
94 
95 #ifndef SWIG
96 /** Define one of these in C++ to add a new int flag storing
97  into the passed variable.
98 
99  \note You should consider using Flag<std::string> instead.
100 */
101 struct IMPBASEEXPORT AddStringFlag {
102  AddStringFlag(std::string name, std::string description,
103  std::string *storage);
104 };
105 #endif
106 
107 /** For python use.*/
108 IMPBASEEXPORT void add_string_flag(std::string name, std::string default_value,
109  std::string description);
110 /** For python use.*/
111 IMPBASEEXPORT std::string get_string_flag(std::string name);
112 
113 #ifndef SWIG
114 /** Define one of these in C++ to add a new boost::int64_t flag storing
115  into the passed variable.
116 
117  \note You should consider using Flag<boost::int64_t> instead.
118 */
119 struct IMPBASEEXPORT AddIntFlag {
120  AddIntFlag(std::string name, std::string description,
121  boost::int64_t *storage);
122 };
123 #endif
124 
125 /** For python use.*/
126 IMPBASEEXPORT void add_int_flag(std::string name, size_t default_value,
127  std::string description);
128 /** For python use.*/
129 IMPBASEEXPORT size_t get_int_flag(std::string name);
130 
131 #ifndef SWIG
132 /** Define one of these in C++ to add a new bool flag storing
133  into the passed variable.
134 
135  \note You should consider using Flag<bool> instead.
136 */
137 struct IMPBASEEXPORT AddBoolFlag {
138  AddBoolFlag(std::string name, std::string description, bool *storage);
139 };
140 #endif
141 
142 /** For python use. Default is always false.*/
143 IMPBASEEXPORT void add_bool_flag(std::string name, std::string description);
144 /** For python use.*/
145 IMPBASEEXPORT bool get_bool_flag(std::string name);
146 
147 #ifndef SWIG
148 /** Define one of these in C++ to add a new float flag storing
149  into the passed variable.
150 
151  \note You should consider using Flag<double> instead.
152 */
153 struct IMPBASEEXPORT AddFloatFlag {
154  AddFloatFlag(std::string name, std::string description, double *storage);
155 };
156 #endif
157 
158 /** For python use.*/
159 IMPBASEEXPORT void add_float_flag(std::string name, double default_value,
160  std::string description);
161 /** For python use.*/
162 IMPBASEEXPORT double get_float_flag(std::string name);
163 /** @} */
164 
165 /** Prints out the help message, useful if you have extra error checking
166  and the flags don't pass it.*/
167 IMPBASEEXPORT void write_help(std::ostream &out = std::cerr);
168 
169 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
170 /* Exposing global variables through swig is kind of broken,
171  see issue #723. */
172 extern IMPBASEEXPORT AdvancedFlag<bool> run_quick_test;
173 #endif
174 // defined in static.cpp
175 
176 /** Executables can inspect this flag and when it is true, run a shorter,
177  simpler version of their code to just make sure things work.
178 */
179 inline bool get_is_quick_test() { return run_quick_test; }
180 
181 IMPBASE_END_NAMESPACE
182 
183 #endif /* IMPBASE_FLAGS_H */
Basic types used by IMP.
bool get_is_quick_test()
Definition: base/flags.h:179
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: base/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)
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()