A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
options.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_CORE_OPTIONS_H_
2 #define GENESIS_UTILS_CORE_OPTIONS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <random>
35 #include <string>
36 #include <vector>
37 
38 namespace genesis {
39 namespace utils {
40 
41 // =================================================================================================
42 // Options
43 // =================================================================================================
44 
48 class Options
49 {
50 public:
51 
52  // -------------------------------------------------------------------------
53  // Instance
54  // -------------------------------------------------------------------------
55 
59  inline static Options& get() {
60  // Meyers-Singleton
61  static Options instance;
62  return instance;
63  }
64 
65  // -------------------------------------------------------------------------
66  // Command Line
67  // -------------------------------------------------------------------------
68 
72  inline std::vector<std::string> command_line() const
73  {
74  return command_line_;
75  }
76 
80  std::string command_line_string() const;
81 
88  void command_line( int const argc, char const* const* argv );
89 
90  // -------------------------------------------------------------------------
91  // Number of Threads
92  // -------------------------------------------------------------------------
93 
97  inline unsigned int number_of_threads() const
98  {
99  return number_of_threads_;
100  }
101 
111  void number_of_threads( unsigned int number );
112 
116  bool using_pthreads() const;
117 
121  bool using_openmp() const;
122 
123  // -------------------------------------------------------------------------
124  // Random Seed & Engine
125  // -------------------------------------------------------------------------
126 
130  inline unsigned random_seed() const
131  {
132  return random_seed_;
133  }
134 
141  void random_seed (const unsigned seed);
142 
154  inline std::default_random_engine& random_engine()
155  {
156  return random_engine_;
157  }
158 
159  // -------------------------------------------------------------------------
160  // Misc Options
161  // -------------------------------------------------------------------------
162 
168  inline bool allow_file_overwriting() const
169  {
170  return allow_file_overwriting_;
171  }
172 
184  inline void allow_file_overwriting( bool value )
185  {
186  allow_file_overwriting_ = value;
187  }
188 
189  // -------------------------------------------------------------------------
190  // Run Time Environment
191  // -------------------------------------------------------------------------
192 
197  bool stdin_is_terminal() const;
198 
203  bool stdout_is_terminal() const;
204 
209  bool stderr_is_terminal() const;
210 
211  // -------------------------------------------------------------------------
212  // Compile Time Environment
213  // -------------------------------------------------------------------------
214 
218  static bool is_little_endian();
219 
223  static bool is_big_endian();
224 
230  static std::string platform();
231 
237  static std::string compiler_family();
238 
244  static std::string compiler_version();
245 
249  static std::string cpp_version();
250 
251  // -------------------------------------------------------------------------
252  // Build Type
253  // -------------------------------------------------------------------------
254 
255  #if defined( DEBUG ) && defined( NDEBUG )
256  static_assert( false, "Cannot compile with both DEBUG and NDEBUG flags set." );
257  #endif
258 
259  #if ! defined( DEBUG ) && ! defined( NDEBUG )
260  static_assert( false, "Cannot compile with neiher DEBUG nor NDEBUG flag set." );
261  #endif
262 
266  static bool is_debug();
267 
271  static bool is_release();
272 
276  static std::string build_type();
277 
278  // -------------------------------------------------------------------------
279  // Dump & Overview
280  // -------------------------------------------------------------------------
281 
285  std::string info() const;
286 
287  // -------------------------------------------------------------------------
288  // Data Members
289  // -------------------------------------------------------------------------
290 
291 private:
292 
293  std::vector<std::string> command_line_;
294  unsigned int number_of_threads_;
295 
296  unsigned random_seed_;
297  std::default_random_engine random_engine_;
298 
299  bool allow_file_overwriting_ = false;
300 
301  // -------------------------------------------------------------------------
302  // Hidden Class Members
303  // -------------------------------------------------------------------------
304 
305 private:
306 
307  // Everything private, as it is a singleton.
308 
312  Options();
313 
314  ~Options() = default;
315 
316  Options( const Options& ) = delete;
317  Options( Options&& ) = delete;
318  Options& operator= ( const Options& ) = delete;
319  Options& operator= ( Options&& ) = delete;
320 
321 };
322 
323 } // namespace utils
324 } // namespace genesis
325 
326 #endif // include guard
static std::string cpp_version()
Return the CPP version that was used to compile genesis.
Definition: options.cpp:273
bool stdout_is_terminal() const
Return true iff the standard output stream is a terminal, and false if not, i.e., if it is a file or ...
Definition: options.cpp:173
void allow_file_overwriting(bool value)
Set whether Genesis is allowed to overwrite files when outputting data.
Definition: options.hpp:184
static std::string compiler_version()
Return the compiler version that was used to compile genesis.
Definition: options.cpp:247
static std::string platform()
Return the platform under which genesis was compiled.
Definition: options.cpp:207
unsigned int number_of_threads() const
Returns the number of threads.
Definition: options.hpp:97
static std::string compiler_family()
Return the compiler family (name) that was used to compile genesis.
Definition: options.cpp:224
bool using_pthreads() const
Return whether the binary was compiled using Pthreads.
Definition: options.cpp:131
static bool is_debug()
Return whether the binary was compiled with build type DEBUG.
Definition: options.cpp:286
std::vector< std::string > command_line() const
Returns an array of strings containing the program's command line arguments.
Definition: options.hpp:72
std::string command_line_string() const
Returns a string containing the program's command line arguments.
Definition: options.cpp:89
static bool is_release()
Return whether the binary was compiled with build type RELEASE.
Definition: options.cpp:295
std::default_random_engine & random_engine()
Returns the default engine for random number generation.
Definition: options.hpp:154
unsigned random_seed() const
Returns the random seed that was used to initialize the engine.
Definition: options.hpp:130
bool stdin_is_terminal() const
Return true iff the standard input stream is a terminal, and false if not, i.e., if it is a file or a...
Definition: options.cpp:163
std::string info() const
Return a list with compile time and run time options with their values.
Definition: options.cpp:319
static std::string build_type()
Return the build type that was used to compile the binary, i.e., "debug" or "release".
Definition: options.cpp:304
static bool is_big_endian()
Return whether the system uses big endian memory.
Definition: options.cpp:201
bool allow_file_overwriting() const
Get whether Genesis is allowed to overwrite files when outputting data.
Definition: options.hpp:168
bool using_openmp() const
Return whether the binary was compiled using OpenMP.
Definition: options.cpp:140
static bool is_little_endian()
Return whether the system uses little endian memory.
Definition: options.cpp:195
bool stderr_is_terminal() const
Return true iff the standard error stream is a terminal, and false if not, i.e., if it is a file or a...
Definition: options.cpp:182
Simple Options class for application-wide configuration and settings.
Definition: options.hpp:48