A toolkit for working with phylogenetic data.
v0.20.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 <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 
117  bool using_pthreads() const;
118 
122  bool using_openmp() const;
123 
124  // -------------------------------------------------------------------------
125  // Random Seed & Engine
126  // -------------------------------------------------------------------------
127 
131  inline unsigned random_seed() const
132  {
133  return random_seed_;
134  }
135 
142  void random_seed (const unsigned seed);
143 
155  inline std::default_random_engine& random_engine()
156  {
157  return random_engine_;
158  }
159 
160  // -------------------------------------------------------------------------
161  // Misc Options
162  // -------------------------------------------------------------------------
163 
169  inline bool allow_file_overwriting() const
170  {
171  return allow_file_overwriting_;
172  }
173 
185  inline void allow_file_overwriting( bool value )
186  {
187  allow_file_overwriting_ = value;
188  }
189 
190  // -------------------------------------------------------------------------
191  // Run Time Environment
192  // -------------------------------------------------------------------------
193 
198  bool stdin_is_terminal() const;
199 
204  bool stdout_is_terminal() const;
205 
210  bool stderr_is_terminal() const;
211 
216  std::pair<int, int> terminal_size() const;
217 
218  // -------------------------------------------------------------------------
219  // Compile Time Environment
220  // -------------------------------------------------------------------------
221 
225  static bool is_little_endian();
226 
230  static bool is_big_endian();
231 
237  static std::string platform();
238 
244  static std::string compiler_family();
245 
251  static std::string compiler_version();
252 
256  static std::string cpp_version();
257 
258  // -------------------------------------------------------------------------
259  // Build Type
260  // -------------------------------------------------------------------------
261 
265  static bool is_debug();
266 
270  static bool is_release();
271 
275  static std::string build_type();
276 
277  // -------------------------------------------------------------------------
278  // Object Info & Overview
279  // -------------------------------------------------------------------------
280 
296  inline void print_object_infos( bool value )
297  {
298  print_obj_infos_ = value;
299  }
300 
306  inline bool print_object_infos() const
307  {
308  return print_obj_infos_;
309  }
310 
327  inline void print_object_gists( long value )
328  {
329  print_obj_gists_ = value;
330  }
331 
337  inline long print_object_gists() const
338  {
339  return print_obj_gists_;
340  }
341 
345  std::string info() const;
346 
347  // -------------------------------------------------------------------------
348  // Data Members
349  // -------------------------------------------------------------------------
350 
351 private:
352 
353  std::vector<std::string> command_line_;
354  unsigned int number_of_threads_;
355 
356  unsigned random_seed_;
357  std::default_random_engine random_engine_;
358 
359  bool allow_file_overwriting_ = false;
360 
361  bool print_obj_infos_ = true;
362  long print_obj_gists_ = 0;
363 
364  // -------------------------------------------------------------------------
365  // Hidden Class Members
366  // -------------------------------------------------------------------------
367 
368 private:
369 
370  // Everything private, as it is a singleton.
371 
375  Options();
376 
377  ~Options() = default;
378 
379  Options( const Options& ) = delete;
380  Options( Options&& ) = delete;
381  Options& operator= ( const Options& ) = delete;
382  Options& operator= ( Options&& ) = delete;
383 
384 };
385 
386 } // namespace utils
387 } // namespace genesis
388 
389 #endif // include guard
static std::string cpp_version()
Return the CPP version that was used to compile genesis.
Definition: options.cpp:307
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:187
void allow_file_overwriting(bool value)
Set whether Genesis is allowed to overwrite files when outputting data.
Definition: options.hpp:185
static std::string compiler_version()
Return the compiler version that was used to compile genesis.
Definition: options.cpp:281
static std::string platform()
Return the platform under which genesis was compiled.
Definition: options.cpp:241
unsigned int number_of_threads() const
Returns the number of threads.
Definition: options.hpp:98
static std::string compiler_family()
Return the compiler family (name) that was used to compile genesis.
Definition: options.cpp:258
bool using_pthreads() const
Return whether the binary was compiled using Pthreads.
Definition: options.cpp:145
static bool is_debug()
Return whether the binary was compiled with build type DEBUG.
Definition: options.cpp:320
std::vector< std::string > command_line() const
Returns an array of strings containing the program's command line arguments.
Definition: options.hpp:73
std::pair< int, int > terminal_size() const
Return the width and height of the terminal that is used to run the program, in number of columns and...
Definition: options.cpp:205
bool print_object_infos() const
Get whether an object info one-liner is printed when using the operator <<.
Definition: options.hpp:306
std::string command_line_string() const
Returns a string containing the program's command line arguments.
Definition: options.cpp:100
long print_object_gists() const
Get whether an object gist is printed when using the operator <<.
Definition: options.hpp:337
static bool is_release()
Return whether the binary was compiled with build type RELEASE.
Definition: options.cpp:329
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:296
std::default_random_engine & random_engine()
Returns the default engine for random number generation.
Definition: options.hpp:155
unsigned random_seed() const
Returns the random seed that was used to initialize the engine.
Definition: options.hpp:131
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:177
std::string info() const
Return a list with compile time and run time options with their values.
Definition: options.cpp:353
static std::string build_type()
Return the build type that was used to compile the binary, i.e., "debug" or "release".
Definition: options.cpp:338
static bool is_big_endian()
Return whether the system uses big endian memory.
Definition: options.cpp:235
bool allow_file_overwriting() const
Get whether Genesis is allowed to overwrite files when outputting data.
Definition: options.hpp:169
bool using_openmp() const
Return whether the binary was compiled using OpenMP.
Definition: options.cpp:154
static bool is_little_endian()
Return whether the system uses little endian memory.
Definition: options.cpp:229
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:196
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:327
Simple Options class for application-wide configuration and settings.
Definition: options.hpp:49