ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utils.h
Go to the documentation of this file.
1 
11 #ifndef _UTILS_H_
12 #define _UTILS_H_
13 
14 #ifdef __GNUC__
15 #define SUPPRESS_NOT_USED_WARN __attribute__ ((unused))
16 #else
17 #define SUPPRESS_NOT_USED_WARN
18 #endif
19 
20 #include <iostream>
21 #include <vector>
22 #include <sstream>
23 #include <cstdlib>
24 
32 namespace Utils
33 {
34  // should not be const if we want to change (unit-tests for instance)
36  //const std::string PATH_DATA="/home/michael/workspace_kepler/ROOT_application/data";
37  // set directory for tests, unit-tests
38  const std::string PATH_DATA_TEST="/home/michael/workspace_kepler/ROOT_application/data_test";
39 
45  void SetPathData( std::string new_path );
46  std::string GetPathData();
47 
51  const time_t ERROR_StrToTime = -105;
52 
54  struct firstlast_dates {
55  time_t first;
56  time_t last;
57  };
58 
61  firstlast_dates def;
62  def.first = 0;
63  def.last = 0;
64  return def;
65  }
66 
67  // need to write code here for instantiation of template
68  template<class T>
69  std::string toString(const T& t)
70  {
71  std::ostringstream stream;
72  stream << t;
73  return stream.str();
74  }
75 
77  template<class T>
78  T fromString(const std::string& s)
79  {
80  std::istringstream stream (s);
81  T t;
82  stream >> t;
83  return t;
84  // could test the conversion
85  //return !(iss >> f >> t).fail();
86  }
87 
88 
94 #ifndef __CINT__
95  double fromStreamToDouble( std::iostream& stream, char delim );
96 #endif
97 
99  void splitline(const std::string& str, const std::string& delimiters , std::vector<std::string>& tokens);
100 
102 
104  time_t GetTime_tToday();
105 
115  time_t StringToTime_t ( const std::string& str );
126  time_t StringToTime_t ( const char * str );
127 
134  std::string Time_tToString ( const time_t& time, const bool b_hour=false );
143  void GetDateYMD( time_t time_unix, int& year, int& month, int& day );
144 
145 } //end namespace Utils
146 
147 #endif /* _UTILS_H_ */
148 
const std::string PATH_DATA_TEST
Important variable to adjust before compilation, should be in a configuration.
Definition: Utils.h:38
double fromStreamToDouble(std::iostream &stream, char delim)
Read the next character of a stream as a double.
Definition: Utils.cpp:45
void SetPathData(std::string new_path)
forced to use this function now.
Definition: Utils.cpp:37
T fromString(const std::string &s)
Transform string to any type : float, double, int.
Definition: Utils.h:78
time_t GetTime_tToday()
Get the time_t of today.
Definition: Utils.cpp:74
const time_t ERROR_StrToTime
Error code returned by StringToTime_t if the string cannot be parsed correctly Must be a time_t...
Definition: Utils.h:51
std::string toString(const T &t)
Definition: Utils.h:69
std::string Time_tToString(const time_t &time, const bool b_hour)
Return a string representing the date All times are expressed in the localtime.
Definition: Utils.cpp:157
void GetDateYMD(time_t time_unix, int &year, int &month, int &day)
Set year, month and day given an input time.
Definition: Utils.cpp:185
time_t StringToTime_t(const std::string &str_date)
Return the time_t from a string .
Definition: Utils.cpp:93
std::string GetPathData()
Definition: Utils.cpp:42
static SUPPRESS_NOT_USED_WARN firstlast_dates get_fldate_default()
need to be static for using default argument in a function
Definition: Utils.h:60
void splitline(const std::string &str, const std::string &delimiters, std::vector< std::string > &tokens)
splitline
Definition: Utils.cpp:56
general structure for dates in csv files
Definition: Utils.h:54
#define SUPPRESS_NOT_USED_WARN
Definition: Utils.h:17