Pteros  2.0
Molecular modeling library for human beings!
utils.h
1 // Copyright Maarten L. Hekkelman, Radboud University 2008-2011.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 #pragma once
7 
8 #ifndef NDEBUG
9 #include <iostream>
10 #endif
11 
12 #include <time.h>
13 //#include <boost/thread.hpp>
14 #include <boost/lexical_cast.hpp>
15 #include <boost/format.hpp>
16 #include <boost/filesystem.hpp>
17 
18 // --------------------------------------------------------------------
19 
20 class arg_vector
21 {
22  public:
23 
24  arg_vector(const std::string& program)
25  {
26  m_args.push_back(program);
27  }
28 
29  void push(const std::string& option)
30  {
31  m_args.push_back(option);
32  }
33 
34  template<class T>
35  void push(const std::string& option, const T& value);
36 
37  operator char* const*();
38 
39  private:
40  friend std::ostream& operator<<(std::ostream& os, const arg_vector& argv);
41 
42  std::vector<std::string> m_args;
43  std::vector<const char*> m_argv;
44 };
45 
46 template<class T>
47 inline
48 void arg_vector::push(const std::string& option, const T& value)
49 {
50  m_args.push_back(option);
51  m_args.push_back(boost::lexical_cast<std::string>(value));
52 }
53 
54 template<>
55 inline
56 void arg_vector::push(const std::string& option, const std::string& value)
57 {
58  m_args.push_back(option);
59  m_args.push_back(value);
60 }
61 
62 std::ostream& operator<<(std::ostream& os, const arg_vector& argv);
63 
64 // --------------------------------------------------------------------
65 
66 class mas_exception : public std::exception
67 {
68  public:
69  mas_exception(const std::string& msg);
70  mas_exception(const boost::format& msg);
71 
72  virtual const char*
73  what() const throw() { return m_msg; }
74 
75  private:
76  char m_msg[1024];
77 };
78 
79 // --------------------------------------------------------------------
80 
81 #ifndef NDEBUG
82 struct stats
83 {
84  stats() : m_max(0), m_count(0), m_cumm(0) {}
85  ~stats();
86 
87  void operator()(uint32 i)
88  {
89  if (m_max < i)
90  m_max = i;
91  ++m_count;
92  m_cumm += i;
93  }
94 
95  uint32 m_max, m_count, m_cumm;
96 };
97 #endif
98 
99 // --------------------------------------------------------------------
100 
101 void WriteToFD(int inFD, const std::string& inText);
102 boost::filesystem::path get_home();