A toolkit for working with phylogenetic data.
v0.18.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-2017 Lucas Czech
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 
108  void number_of_threads (const unsigned int number);
109 
113  bool using_pthreads() const;
114 
118  bool using_openmp() const;
119 
120  // -------------------------------------------------------------------------
121  // Random Seed & Engine
122  // -------------------------------------------------------------------------
123 
127  inline unsigned random_seed() const
128  {
129  return random_seed_;
130  }
131 
138  void random_seed (const unsigned seed);
139 
151  inline std::default_random_engine& random_engine()
152  {
153  return random_engine_;
154  }
155 
156  // -------------------------------------------------------------------------
157  // Misc Options
158  // -------------------------------------------------------------------------
159 
165  inline bool allow_file_overwriting() const
166  {
167  return allow_file_overwriting_;
168  }
169 
181  inline void allow_file_overwriting( bool value )
182  {
183  allow_file_overwriting_ = value;
184  }
185 
186  // -------------------------------------------------------------------------
187  // Run Time Environment
188  // -------------------------------------------------------------------------
189 
194  bool stdin_is_terminal() const;
195 
200  bool stdout_is_terminal() const;
201 
206  bool stderr_is_terminal() const;
207 
208  // -------------------------------------------------------------------------
209  // Compile Time Environment
210  // -------------------------------------------------------------------------
211 
215  static bool is_little_endian();
216 
220  static bool is_big_endian();
221 
227  static std::string platform();
228 
234  static std::string compiler_family();
235 
241  static std::string compiler_version();
242 
246  static std::string cpp_version();
247 
248  // -------------------------------------------------------------------------
249  // Build Type
250  // -------------------------------------------------------------------------
251 
252  #if defined( DEBUG ) && defined( NDEBUG )
253  static_assert( false, "Cannot compile with both DEBUG and NDEBUG flags set." );
254  #endif
255 
256  #if ! defined( DEBUG ) && ! defined( NDEBUG )
257  static_assert( false, "Cannot compile with neiher DEBUG nor NDEBUG flag set." );
258  #endif
259 
263  static bool is_debug();
264 
268  static bool is_release();
269 
273  static std::string build_type();
274 
275  // -------------------------------------------------------------------------
276  // Dump & Overview
277  // -------------------------------------------------------------------------
278 
282  std::string info() const;
283 
284  // -------------------------------------------------------------------------
285  // Data Members
286  // -------------------------------------------------------------------------
287 
288 private:
289 
290  std::vector<std::string> command_line_;
291  unsigned int number_of_threads_;
292 
293  unsigned random_seed_;
294  std::default_random_engine random_engine_;
295 
296  bool allow_file_overwriting_ = false;
297 
298  // -------------------------------------------------------------------------
299  // Hidden Class Members
300  // -------------------------------------------------------------------------
301 
302 private:
303 
304  // Everything private, as it is a singleton.
305 
309  Options();
310 
311  ~Options() = default;
312 
313  Options( const Options& ) = delete;
314  Options( Options&& ) = delete;
315  Options& operator= ( const Options& ) = delete;
316  Options& operator= ( Options&& ) = delete;
317 
318 };
319 
320 } // namespace utils
321 } // namespace genesis
322 
323 #endif // include guard
static std::string cpp_version()
Return the CPP version that was used to compile genesis.
Definition: options.cpp:266
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:166
void allow_file_overwriting(bool value)
Set whether Genesis is allowed to overwrite files when outputting data.
Definition: options.hpp:181
static std::string compiler_version()
Return the compiler version that was used to compile genesis.
Definition: options.cpp:240
static std::string platform()
Return the platform under which genesis was compiled.
Definition: options.cpp:200
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:217
bool using_pthreads() const
Return whether the binary was compiled using Pthreads.
Definition: options.cpp:124
static bool is_debug()
Return whether the binary was compiled with build type DEBUG.
Definition: options.cpp:279
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:288
std::default_random_engine & random_engine()
Returns the default engine for random number generation.
Definition: options.hpp:151
unsigned random_seed() const
Returns the random seed that was used to initialize the engine.
Definition: options.hpp:127
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:156
std::string info() const
Return a list with compile time and run time options with their values.
Definition: options.cpp:312
static std::string build_type()
Return the build type that was used to compile the binary, i.e., "debug" or "release".
Definition: options.cpp:297
static bool is_big_endian()
Return whether the system uses big endian memory.
Definition: options.cpp:194
bool allow_file_overwriting() const
Get whether Genesis is allowed to overwrite files when outputting data.
Definition: options.hpp:165
bool using_openmp() const
Return whether the binary was compiled using OpenMP.
Definition: options.cpp:133
static bool is_little_endian()
Return whether the system uses little endian memory.
Definition: options.cpp:188
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:175
Simple Options class for application-wide configuration and settings.
Definition: options.hpp:48