ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimeScale.cpp
Go to the documentation of this file.
1 
8 // ETime now declared out of namescape
9 #include "TimeScale.h"
10 
11 namespace TimeScale {
12 
13 // fixed unsigned int for Etime, works as well. Can test/change easily later.
14 //unsigned int as_int(ETime time) {return static_cast<unsigned int>(time);}
15 
16 // http://stackoverflow.com/questions/11421432/how-can-i-output-the-value-of-an-enum-class-in-c11
17 std::ostream& operator << (std::ostream& os, const ETime& obj)
18 {
19  //os << static_cast<std::underlying_type<ETime>::type>(obj);
20  os << TimeScale::GetTimeScaleName( obj );
21  return os;
22 }
23 
24 std::string GetTimeScaleName ( const ETime& tmscl )
25  {
26  switch ( tmscl ) {
27 
28  case ETime::INST :
29  return "INST";
30  case ETime::M5 :
31  return "M5";
32  case ETime::M10 :
33  return "M10";
34  case ETime::M30 :
35  return "M30";
36  case ETime::H1 :
37  return "H1";
38  case ETime::DAY:
39  return "DAY";
40  case ETime::WEEK:
41  return "WEEK";
42  case ETime::MONTH:
43  return "MONTH";
44  case ETime::TRIM :
45  return "TRIM";
46  case ETime::YEAR :
47  return "YEAR";
48  // case not_a_date
49  default:
50  return "Not a time";
51  }
52  }
53 
54  ETime GetTimeScaleFromName ( const std::string& tmscl_str )
55  {
56  if ( tmscl_str == "INST" )
57  return ETime::INST;
58  else if ( tmscl_str == "M5" )
59  return ETime::M5;
60  else if ( tmscl_str == "M10" )
61  return ETime::M10;
62  else if ( tmscl_str == "M30" )
63  return ETime::M30;
64  else if ( tmscl_str == "H1" )
65  return ETime::H1;
66 
67  else if ( tmscl_str == "DAY" )
68  return ETime::DAY;
69  else if ( tmscl_str == "WEEK" )
70  return ETime::WEEK;
71  else if ( tmscl_str == "MONTH" )
72  return ETime::MONTH;
73  else if ( tmscl_str == "TRIM" )
74  return ETime::TRIM;
75  else if ( tmscl_str == "YEAR" )
76  return ETime::YEAR;
77  // default, problem
78  else {
79  std::cout << "/nError TimeScale::GetTimeScaleFromName return default ETime::not_a_time" << std::endl;
80  return ETime::not_a_time;
81  }
82  }
83 
84 }
Define Time period information for the data.
std::ostream & operator<<(std::ostream &os, const ETime &obj)
allow to print the string format "DAY", to get the integer use TimeScale::as_uint() function ...
Definition: TimeScale.cpp:17
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
Definition: TimeScale.h:48
ETime GetTimeScaleFromName(const std::string &tmscl_str)
From name "DAY", get ETime::DAY.
Definition: TimeScale.cpp:54
std::string GetTimeScaleName(const ETime &tmscl)
Get the string, i.e., "DAY".
Definition: TimeScale.cpp:24