IMP  2.1.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-2012 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 struct IMPBASEEXPORT AddStringFlag {
99  AddStringFlag(std::string name, std::string description,
100  std::string *storage);
101 };
102 #endif
103 
104 /** For python use.*/
105 IMPBASEEXPORT void add_string_flag(std::string name, std::string default_value,
106  std::string description);
107 /** For python use.*/
108 IMPBASEEXPORT std::string get_string_flag(std::string name);
109 
110 #ifndef SWIG
111 /** Define one of these in C++ to add a new boost::int64_t flag storing
112  into the passed variable.*/
113 struct IMPBASEEXPORT AddIntFlag {
114  AddIntFlag(std::string name, std::string description,
115  boost::int64_t *storage);
116 };
117 #endif
118 
119 /** For python use.*/
120 IMPBASEEXPORT void add_int_flag(std::string name, size_t default_value,
121  std::string description);
122 /** For python use.*/
123 IMPBASEEXPORT size_t get_int_flag(std::string name);
124 
125 #ifndef SWIG
126 /** Define one of these in C++ to add a new bool flag storing
127  into the passed variable.*/
128 struct IMPBASEEXPORT AddBoolFlag {
129  AddBoolFlag(std::string name, std::string description, bool *storage);
130 };
131 #endif
132 
133 /** For python use. Default is always false.*/
134 IMPBASEEXPORT void add_bool_flag(std::string name, std::string description);
135 /** For python use.*/
136 IMPBASEEXPORT bool get_bool_flag(std::string name);
137 
138 #ifndef SWIG
139 /** Define one of these in C++ to add a new float flag storing
140  into the passed variable.*/
141 struct IMPBASEEXPORT AddFloatFlag {
142  AddFloatFlag(std::string name, std::string description, double *storage);
143 };
144 #endif
145 
146 /** For python use.*/
147 IMPBASEEXPORT void add_float_flag(std::string name, double default_value,
148  std::string description);
149 /** For python use.*/
150 IMPBASEEXPORT double get_float_flag(std::string name);
151 /** @} */
152 
153 /** Prints out the help message, useful if you have extra error checking
154  and the flags don't pass it.*/
155 IMPBASEEXPORT void write_help(std::ostream &out = std::cerr);
156 
157 /** Executables can inspect this flag and when it is true, run a shorter,
158  simpler version of their code to just make sure things work.
159 */
160 extern IMPBASEEXPORT bool run_quick_test;
161 // defined in static.cpp
162 
163 IMPBASE_END_NAMESPACE
164 
165 #endif /* IMPBASE_FLAGS_H */
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: base/types.h:51
bool run_quick_test
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_allowing_unknown(int argc, char **argv, std::string description)
void setup_from_argv(int argc, char **argv, std::string description)
std::string get_executable_name()