IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
Flag.h
Go to the documentation of this file.
1/**
2 * \file IMP/Flag.h
3 * \brief Utility classes to add command line flags.
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef IMPKERNEL_FLAG_H
10#define IMPKERNEL_FLAG_H
11
12#include <IMP/kernel_config.h>
13#include "internal/Flag.h"
14#include <boost/program_options.hpp>
15#include <string>
16
17#ifndef IMP_DOXYGEN
18
19IMPKERNEL_BEGIN_INTERNAL_NAMESPACE
20extern IMPKERNELEXPORT boost::program_options::options_description flags;
21extern IMPKERNELEXPORT boost::program_options::options_description advanced_flags;
22IMPKERNEL_END_INTERNAL_NAMESPACE
23#endif
24
25IMPKERNEL_BEGIN_NAMESPACE
26
27/** Use this to add a flag to the program. It is convertible to the
28passed type and so can be used as the value itself.
29
30The ENABLED template argument is to allow the preprocessor to turn it
31on or off (eg pass IMP_HAS_XXX).
32
33The Flag can be used like an instance of type T.
34*/
35template <class T, bool ENABLED = true>
36class 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/** Such flags are not shown unless requested (using `--help_advanced`).
49
50 \see Flag for more info.
51*/
52template <class T, bool ENABLED = true>
53class AdvancedFlag : public internal::FlagImpl<T, ENABLED> {
54
55 public:
56 AdvancedFlag(std::string name, std::string description, T default_value = T())
57 : internal::FlagImpl<T, ENABLED>(internal::advanced_flags, name,
58 description, default_value) {}
59 AdvancedFlag<T, ENABLED>& operator=(const T& o) {
60 internal::FlagImpl<T, ENABLED>::operator=(o);
61 return *this;
62 }
63};
64
65IMPKERNEL_END_NAMESPACE
66
67#endif /* IMPKERNEL_FLAG_H */