IMP  2.0.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-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 line flags to \imp.
21  Programs that use this have access to flags declared in modules
22  which allow users to do things like control log level and turn
23  on and off profiling to see what is going on. These functions
24  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 */
30 
31 /** Return the name of the current executable.*/
32 IMPBASEEXPORT std::string get_executable_name();
33 
34 #ifndef SWIG
35 /** Parse the command line flags and return the
36  positional arguments.
37 
38  \param[in] argc argc
39  \param[in] argv argv
40  \param[in] description A message describing what the program does.
41  */
42 IMPBASEEXPORT void
43 setup_from_argv(int argc, char ** argv,
44  std::string description);
45 
46 /** Parse the command line flags and return the
47  positional arguments.
48 
49  \param[in] argc argc
50  \param[in] argv argv
51  \param[in] description A message describing what the program does.
52  \param[in] positional_description A message describing the the
53  positional arguments
54  \param[in] num_positional A positive integer to require that
55  many positional arguments, or a negative integer to require at
56  least that many.
57  */
58 IMPBASEEXPORT Strings
59 setup_from_argv(int argc, char ** argv,
60  std::string description,
61  std::string positional_description,
62  int num_positional);
63 #endif
64 
65 /** Parse the command line flags and return the
66  positional arguments. For python.
67 
68  \param[in] argv sys.argv
69  \param[in] description A message describing what the program does.
70  */
71 IMPBASEEXPORT
72 void setup_from_argv(const Strings& argv,
73  std::string description);
74 
75 /** Parse the command line flags and return the
76  positional arguments. For python.
77 
78  \param[in] argv sys.argv
79  \param[in] description A message describing what the program does.
80  \param[in] positional_description A message describing the positional
81  arguments, eg "input.pdb output.pdb"
82  \param[in] num_positional A positive integer to require that
83  many positional arguments, or a negative integer to require at
84  least that many.
85  */
86 IMPBASEEXPORT Strings
87 setup_from_argv(const Strings& argv,
88  std::string description,
89  std::string positional_description,
90  int num_positional);
91 
92 #ifndef SWIG
93 /** Define one of these in C++ to add a new int flag storing
94  into the passed variable.*/
95 struct IMPBASEEXPORT AddStringFlag {
96  AddStringFlag(std::string name,
97  std::string description,
98  std::string *storage);
99 };
100 #endif
101 
102 /** For python use.*/
103 IMPBASEEXPORT void add_string_flag(std::string name,
104  std::string default_value,
105  std::string description);
106 /** For python use.*/
107 IMPBASEEXPORT std::string get_string_flag(std::string name);
108 
109 #ifndef SWIG
110 /** Define one of these in C++ to add a new boost::int64_t flag storing
111  into the passed variable.*/
112 struct IMPBASEEXPORT AddIntFlag {
113  AddIntFlag(std::string name,
114  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,
121  size_t default_value,
122  std::string description);
123 /** For python use.*/
124 IMPBASEEXPORT size_t get_int_flag(std::string name);
125 
126 #ifndef SWIG
127 /** Define one of these in C++ to add a new bool flag storing
128  into the passed variable.*/
129 struct IMPBASEEXPORT AddBoolFlag {
130  AddBoolFlag(std::string name,
131  std::string description,
132  bool *storage);
133 };
134 #endif
135 
136 /** For python use. Default is always false.*/
137 IMPBASEEXPORT void add_bool_flag(std::string name,
138  std::string description);
139 /** For python use.*/
140 IMPBASEEXPORT bool get_bool_flag(std::string name);
141 
142 #ifndef SWIG
143 /** Define one of these in C++ to add a new float flag storing
144  into the passed variable.*/
145 struct IMPBASEEXPORT AddFloatFlag {
146  AddFloatFlag(std::string name,
147  std::string description,
148  double *storage);
149 };
150 #endif
151 
152 /** For python use.*/
153 IMPBASEEXPORT void add_float_flag(std::string name,
154  double default_value,
155  std::string description);
156 /** For python use.*/
157 IMPBASEEXPORT double get_float_flag(std::string name);
158 /** @} */
159 
160 /** Prints out the help message, useful if you have extra error checking
161  and the flags don't pass it.*/
162 IMPBASEEXPORT void write_help(std::ostream &out= std::cerr);
163 
164 
165 /** Executables can inspect this flag and when it is true, run a shorter,
166  simpler version of their code to just make sure things work.
167 */
168 extern IMPBASEEXPORT bool run_quick_test;
169 // defined in static.cpp
170 
171 IMPBASE_END_NAMESPACE
172 
173 
174 #endif /* IMPBASE_FLAGS_H */