ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimeScale.h
Go to the documentation of this file.
1 
8 #ifndef TIMESCALE_H_
9 #define TIMESCALE_H_
10 
11 #include <iostream>
12 
13 
14 // creates strange error of compiler 4.8, but still compiles !
15 // add CXXFLAGS=-std=c++11, now no error on compilation. But works without include ! by default ??
16 // now ok for C++, but rootcint problem, need to update later (v6 ?)
17 #ifndef __MAKECINT__
18 #include <type_traits>
19 #include <cstdint>
20 #endif
21 
22 // Overhead in including ETime in namespace, works fine,
23 // but need TimeScale::ETime::DAY ...or using namespace TimeScale all the time
24 // It is used very often !
25 // namespace TimeScale
26 // Contains an enumeration class ETime (C++11), and convenient functions
27 //
28 //namespace TimeScale {
29 
30 
31 // use C++11 enum class, can fix format to unsigned int 8, but bad output on screen !
32 //enum class ETime : std::uint8_t { dcsv, M5, M10, M30, H1, DAY, WEEK, MONTH, TRIM, YEAR, not_a_time };
33 
41 // force first to 0, but does not seem necessary
42 #ifdef __MAKECINT__
43  // with traditional enum can compile in namespace also
44  typedef enum { INST=0, M5, M10, M30, H1, DAY, WEEK, MONTH, TRIM, YEAR, not_a_time } ETime;
45 #else
46  // use C++11 enum class, can fix format to unsigned int 8, but bad output on screen with operator << !
47  //enum class ETime : std::uint8_t { INST, M5, M10, M30, H1, DAY, WEEK, MONTH, TRIM, YEAR, not_a_time };
48  enum class ETime : unsigned int { INST=0, M5, M10, M30, H1, DAY, WEEK, MONTH, TRIM, YEAR, not_a_time };
49 #endif
50 
54 namespace TimeScale {
55 // need to be in header
57 // to check if sometimes not needed and implicit
58 template <typename ETime>
59 auto as_uint(ETime const value)
60 // -> typename std::underlying_type<ETime>::type
61  -> unsigned int
62 {
63  //return static_cast<typename std::underlying_type<ETime>::type>(value);
64  return static_cast<unsigned int>(value);
65 }
66 
68 std::ostream& operator << (std::ostream& os, const ETime& obj);
70 std::string GetTimeScaleName ( const ETime& tmscl );
72 ETime GetTimeScaleFromName ( const std::string& tmscl_str );
73 // need GetTimeScaleFromInt, or inverse as_int
74 
75 }
76 
77 #endif /* TIMESCALE_H_ */
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
auto as_uint(ETime const value) -> unsigned int
Provides explicit conversion to unsigned int.
Definition: TimeScale.h:59
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