A toolkit for working with phylogenetic data.
v0.22.1
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-2019 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 <utility>
37 #include <vector>
38 
39 namespace genesis {
40 namespace utils {
41 
42 // =================================================================================================
43 // Options
44 // =================================================================================================
45 
49 class Options
50 {
51 public:
52 
53  // -------------------------------------------------------------------------
54  // Instance
55  // -------------------------------------------------------------------------
56 
60  inline static Options& get() {
61  // Meyers-Singleton
62  static Options instance;
63  return instance;
64  }
65 
66  // -------------------------------------------------------------------------
67  // Command Line
68  // -------------------------------------------------------------------------
69 
73  inline std::vector<std::string> command_line() const
74  {
75  return command_line_;
76  }
77 
81  std::string command_line_string() const;
82 
89  void command_line( int const argc, char const* const* argv );
90 
91  // -------------------------------------------------------------------------
92  // Number of Threads
93  // -------------------------------------------------------------------------
94 
98  inline unsigned int number_of_threads() const
99  {
100  return number_of_threads_;
101  }
102 
112  void number_of_threads( unsigned int number );
113 
120  unsigned int guess_number_of_threads( bool use_openmp = true ) const;
121 
125  bool hyperthreads_enabled() const;
126 
127  // -------------------------------------------------------------------------
128  // Random Seed & Engine
129  // -------------------------------------------------------------------------
130 
134  inline unsigned long random_seed() const
135  {
136  return random_seed_;
137  }
138 
145  void random_seed (const unsigned long seed);
146 
158  inline std::default_random_engine& random_engine()
159  {
160  return random_engine_;
161  }
162 
163  // -------------------------------------------------------------------------
164  // Misc Options
165  // -------------------------------------------------------------------------
166 
172  inline bool allow_file_overwriting() const
173  {
174  return allow_file_overwriting_;
175  }
176 
188  inline void allow_file_overwriting( bool value )
189  {
190  allow_file_overwriting_ = value;
191  }
192 
193  // -------------------------------------------------------------------------
194  // Object Info
195  // -------------------------------------------------------------------------
196 
212  inline void print_object_infos( bool value )
213  {
214  print_obj_infos_ = value;
215  }
216 
222  inline bool print_object_infos() const
223  {
224  return print_obj_infos_;
225  }
226 
243  inline void print_object_gists( long value )
244  {
245  print_obj_gists_ = value;
246  }
247 
253  inline long print_object_gists() const
254  {
255  return print_obj_gists_;
256  }
257 
258  // -------------------------------------------------------------------------
259  // Run Time Environment
260  // -------------------------------------------------------------------------
261 
266  static bool stdin_is_terminal();
267 
272  static bool stdout_is_terminal();
273 
278  static bool stderr_is_terminal();
279 
284  static std::pair<int, int> terminal_size();
285 
286  // -------------------------------------------------------------------------
287  // Compile Time Environment
288  // -------------------------------------------------------------------------
289 
293  static bool is_debug();
294 
298  static bool is_release();
299 
303  static std::string build_type();
304 
308  static bool is_little_endian();
309 
313  static bool is_big_endian();
314 
320  static std::string platform();
321 
327  static std::string compiler_family();
328 
334  static std::string compiler_version();
335 
339  static std::string cpp_version();
340 
347  static std::string compile_date_time();
348 
352  static bool using_pthreads();
353 
357  static bool using_openmp();
358 
362  static bool using_zlib();
363 
364  // -------------------------------------------------------------------------
365  // Overview
366  // -------------------------------------------------------------------------
367 
371  std::string info() const;
372 
373  // -------------------------------------------------------------------------
374  // Data Members
375  // -------------------------------------------------------------------------
376 
377 private:
378 
379  std::vector<std::string> command_line_;
380  unsigned int number_of_threads_;
381 
382  unsigned long random_seed_;
383  std::default_random_engine random_engine_;
384 
385  bool allow_file_overwriting_ = false;
386 
387  bool print_obj_infos_ = true;
388  long print_obj_gists_ = 0;
389 
390  // -------------------------------------------------------------------------
391  // Hidden Class Members
392  // -------------------------------------------------------------------------
393 
394 private:
395 
396  // Everything private, as it is a singleton.
397 
401  Options();
402 
403  ~Options() = default;
404 
405  Options( const Options& ) = delete;
406  Options( Options&& ) = delete;
407  Options& operator= ( const Options& ) = delete;
408  Options& operator= ( Options&& ) = delete;
409 
410 };
411 
412 } // namespace utils
413 } // namespace genesis
414 
415 #endif // include guard
unsigned long random_seed() const
Returns the random seed that was used to initialize the engine.
Definition: options.hpp:134
std::vector< std::string > command_line() const
Returns an array of strings containing the program&#39;s command line arguments.
Definition: options.hpp:73
static std::string cpp_version()
Return the CPP version that was used to compile genesis.
Definition: options.cpp:348
unsigned int guess_number_of_threads(bool use_openmp=true) const
Try to guess the number of hardware threads of the current system.
Definition: options.cpp:143
static bool stderr_is_terminal()
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:208
static bool using_zlib()
Return whether the binary was compiled using zlib.
Definition: options.cpp:380
void allow_file_overwriting(bool value)
Set whether Genesis is allowed to overwrite files when outputting data.
Definition: options.hpp:188
static bool stdout_is_terminal()
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:199
static std::string compiler_version()
Return the compiler version that was used to compile genesis.
Definition: options.cpp:322
static std::string platform()
Return the platform under which genesis was compiled.
Definition: options.cpp:282
static std::string compiler_family()
Return the compiler family (name) that was used to compile genesis.
Definition: options.cpp:299
static bool is_debug()
Return whether the binary was compiled with build type DEBUG.
Definition: options.cpp:241
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
static std::pair< int, int > terminal_size()
Return the width and height of the terminal that is used to run the program, in number of columns and...
Definition: options.cpp:217
bool hyperthreads_enabled() const
Try to get whether hyperthreads are enabled in the current system.
Definition: options.cpp:130
static bool using_openmp()
Return whether the binary was compiled using OpenMP.
Definition: options.cpp:371
static std::string compile_date_time()
Return the date and time when genesis was compiled.
Definition: options.cpp:357
unsigned int number_of_threads() const
Returns the number of threads.
Definition: options.hpp:98
static bool is_release()
Return whether the binary was compiled with build type RELEASE.
Definition: options.cpp:250
std::string command_line_string() const
Returns a string containing the program&#39;s command line arguments.
Definition: options.cpp:85
bool print_object_infos() const
Get whether an object info one-liner is printed when using the operator <<.
Definition: options.hpp:222
void print_object_infos(bool value)
Set whether an object info one-liner is printed when using the operator << that is defined for many c...
Definition: options.hpp:212
static bool stdin_is_terminal()
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:189
std::default_random_engine & random_engine()
Returns the default engine for random number generation.
Definition: options.hpp:158
static std::string build_type()
Return the build type that was used to compile the binary, i.e., "debug" or "release".
Definition: options.cpp:259
static bool is_big_endian()
Return whether the system uses big endian memory.
Definition: options.cpp:276
bool allow_file_overwriting() const
Get whether Genesis is allowed to overwrite files when outputting data.
Definition: options.hpp:172
std::string info() const
Return a list with compile time and run time options with their values.
Definition: options.cpp:393
static bool is_little_endian()
Return whether the system uses little endian memory.
Definition: options.cpp:270
static bool using_pthreads()
Return whether the binary was compiled using Pthreads.
Definition: options.cpp:362
long print_object_gists() const
Get whether an object gist is printed when using the operator <<.
Definition: options.hpp:253
void print_object_gists(long value)
Set whether an object gist is printed when using the operator << that is defined for many (container)...
Definition: options.hpp:243
Simple Options class for application-wide configuration and settings.
Definition: options.hpp:49