IMP  2.2.0
The Integrative Modeling Platform
base/Flag.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/Flag.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_FLAG_H
10 #define IMPBASE_FLAG_H
11 
12 #include <IMP/base/base_config.h>
13 #include "internal/Flag.h"
14 #include <boost/program_options.hpp>
15 #include <string>
16 
17 #ifndef IMP_DOXYGEN
18 
19 IMPBASE_BEGIN_INTERNAL_NAMESPACE
20 extern IMPBASEEXPORT boost::program_options::options_description flags;
21 extern IMPBASEEXPORT boost::program_options::options_description advanced_flags;
22 IMPBASE_END_INTERNAL_NAMESPACE
23 #endif
24 
25 IMPBASE_BEGIN_NAMESPACE
26 
27 /** Use this to add a flag to the program. It is convertible to the
28 passed type and so can be used as the value itself.
29 
30 The ENABLED template argument is to allow the preprocessor to turn it
31 on or off (eg pass IMP_HAS_XXX).
32 
33 The Flag can be used like an instance of type T.
34 */
35 template <class T, bool ENABLED = true>
36 class Flag : public internal::FlagImpl<T, ENABLED> {
37  public:
38  Flag(std::string name, std::string description, T default_value = T())
39  : internal::FlagImpl<T, ENABLED>(internal::flags, name, description,
40  default_value) {}
41  Flag<T, ENABLED>& operator=(const T& o) {
42  internal::FlagImpl<T, ENABLED>::operator=(o);
43  return *this;
44  }
45 };
46 
47 /** Use this to add an advanced flag to the program.
48 
49 Such flags are not shown unless requested (using `--help_advanced`).
50 
51 See Flag for more info.
52 */
53 template <class T, bool ENABLED = true>
54 class AdvancedFlag : public internal::FlagImpl<T, ENABLED> {
55 
56  public:
57  AdvancedFlag(std::string name, std::string description, T default_value = T())
58  : internal::FlagImpl<T, ENABLED>(internal::advanced_flags, name,
59  description, default_value) {}
60  AdvancedFlag<T, ENABLED>& operator=(const T& o) {
61  internal::FlagImpl<T, ENABLED>::operator=(o);
62  return *this;
63  }
64 };
65 
66 IMPBASE_END_NAMESPACE
67 
68 #endif /* IMPBASE_FLAG_H */