Blue Brain BioExplorer
AbstractParameters.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  *
5  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 3.0 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
22 
26 
27 #include <boost/program_options.hpp>
28 #include <boost/program_options/value_semantic.hpp>
29 
30 namespace po = boost::program_options;
31 
32 namespace core
33 {
38 {
39 public:
44  AbstractParameters(const std::string& name)
45  : _name(name)
46  , _parameters(name)
47  {
48  }
49 
50  virtual ~AbstractParameters() = default;
55  virtual void parse(const po::variables_map&){};
56 
60  virtual void print();
61 
62  po::options_description& parameters() { return _parameters; }
63 
64 protected:
65  std::string _name;
66 
67  po::options_description _parameters;
68 
69  static std::string asString(const bool flag) { return flag ? "on" : "off"; }
70 };
71 } // namespace core
72 
73 namespace boost
74 {
75 namespace program_options
76 {
80 template <typename T, typename charT = char>
81 class fixed_tokens_typed_value : public typed_value<T, charT>
82 {
83  const unsigned _min;
84  const unsigned _max;
85 
86  typedef typed_value<T, charT> base;
87 
88 public:
89  fixed_tokens_typed_value(T* t, unsigned min, unsigned max)
90  : base(t)
91  , _min(min)
92  , _max(max)
93  {
94  base::multitoken();
95  }
96  unsigned min_tokens() const { return _min; }
97  unsigned max_tokens() const { return _max; }
98 };
99 
100 template <typename T>
101 inline fixed_tokens_typed_value<T>* fixed_tokens_value(unsigned min, unsigned max)
102 {
103  return new fixed_tokens_typed_value<T>(nullptr, min, max);
104 }
105 
106 template <typename T>
107 inline fixed_tokens_typed_value<T>* fixed_tokens_value(T* t, unsigned min, unsigned max)
108 {
109  return new fixed_tokens_typed_value<T>(t, min, max);
110 }
111 } // namespace program_options
112 } // namespace boost
fixed_tokens_typed_value(T *t, unsigned min, unsigned max)
virtual ~AbstractParameters()=default
virtual void parse(const po::variables_map &)
po::options_description & parameters()
AbstractParameters(const std::string &name)
static std::string asString(const bool flag)
po::options_description _parameters
fixed_tokens_typed_value< T > * fixed_tokens_value(unsigned min, unsigned max)