ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FullName.cpp
Go to the documentation of this file.
1 
7 #include "FullName.h"
8 #include "Utils.h"
9 
11 // only used once, certainly more to use
12 std::string GetString( const Indicator& indic, const std::vector<int>& param ) {
13  std::string str;
14  str = indic.label();
15  for (unsigned int i=0; i < param.size(); i++) {
16  str += '_' + Utils::toString<int>(param[i]);
17  }
18  return str;
19  }
20 
21 /*
22  std::string GetString( const std::string& namestock, const ETime& tmscl,
23  const Indicator& indic, const std::vector<int>& param ) {
24  std::string str;
25  str = namestock + '_';
26  str += GetString( tmscl, indic, param );
27  //std::cout << "I am in FullName::GetString with 4 parameters" << std::endl;
28  return str;
29  }
30 
31  std::string GetString( const ETime& tmscl, const Indicator& indic, const std::vector<int>& param ) {
32  std::string str;
33  //std::cout << "I am in FullName::GetString with 3 parameters" << std::endl;
34  str = TimeScale::GetTimeScaleName( tmscl );
35  str += '_' + indic.label();
36  for (unsigned int i=0; i < param.size(); i++) {
37  str += '_' + Utils::toString<int>(param[i]);
38  }
39  return str;
40  }
41 */
42 
43 namespace FullName
44 {
46  std::string GetNameStock( const std::string & fname ) {
47  std::vector<std::string> vec_substr;
48  Utils::splitline( fname, "_", vec_substr);
49  return vec_substr[0];
50  }
51 
53  ETime GetTimeScale( const std::string& fname ) {
54  std::vector<std::string> vec_substr;
55  Utils::splitline( fname, "_", vec_substr);
56  return TimeScale::GetTimeScaleFromName( vec_substr[1] );
57  }
59  Indicator GetIndicator( const std::string& fname ) {
60  std::vector<std::string> vec_substr;
61  Utils::splitline( fname, "_", vec_substr);
62  return Indicator::GetIndicator( vec_substr[2] );
63  }
65  std::vector<int> GetParams( const std::string& fname ) {
66  std::vector<int> ret_param;
67  std::vector<std::string> vec_substr;
68  Utils::splitline( fname, "_", vec_substr);
69  //std::cout << "GetParams, size after split " << vec_substr.size() << std::endl;
70  for (unsigned int i = 3; i < vec_substr.size(); i++) {
71  //std::cout << " substr " << vec_substr[i] << std::endl;
72  ret_param.push_back( Utils::fromString<int> (vec_substr[i]) );
73  //std::cout << "add param " << ret_param[count++] << std::endl;
74  }
75  return ret_param;
76  }
78  std::string GetShortName( const std::string & fname ) {
79 
80  Indicator indic = GetIndicator( fname );
81  // original std::string shortname = GetIndicator( fname ).label();
82  std::vector<int> vec_params = GetParams( fname );
83  return GetString( indic, vec_params );
90  }
91 
92  std::string GetFrameName( const std::string& fname ) {
93  std::string frame_name = GetNameStock( fname );
94  frame_name += "_" + TimeScale::GetTimeScaleName ( GetTimeScale( fname ) );
95  //std::cout << "FullName GetFrameName " << frame_name << std::endl;
96  return frame_name;
97  }
98 
99 } //end namespace FullName
100 
101 namespace ShortName
102 {
103  Indicator GetIndicator ( const std::string& sname ) {
104  std::vector<std::string> vec_substr;
105  Utils::splitline( sname, "_", vec_substr);
106  return Indicator::GetIndicator( vec_substr[0] );
107  }
108 
109  std::string MakeShortName( const Indicator& indic, const std::vector<int>& param ) {
110  return GetString( indic, param );
111  }
112 } // end namespace ShortName
113 
114 namespace FrameName
115 {
116  std::string GetNameStock( const std::string& frame_name ) {
117  std::vector<std::string> vec_substr;
118  Utils::splitline( frame_name, "_", vec_substr);
119  return ( vec_substr[0] );
120  }
121 
122  ETime GetTimeScale( const std::string& frame_name ) {
123  std::vector<std::string> vec_substr;
124  Utils::splitline( frame_name, "_", vec_substr);
125  return TimeScale::GetTimeScaleFromName( vec_substr[1] );
126  }
127 
128  std::string MakeFrameName( const std::string& namestock, const ETime& tmscl ) {
129  std::string str = namestock + "_" + TimeScale::GetTimeScaleName( tmscl );
130  return str;
131  }
132 } // end namespace FrameName
std::string MakeFrameName(const std::string &namestock, const ETime &tmscl)
Create a frame name string from its components.
Definition: FullName.cpp:128
"Clever" enumeration of the ListDataStock type : StockCSV, Volume, EMA, BOLL,...
Definition: Indicator.h:29
std::string GetString(const Indicator &indic, const std::vector< int > &param)
Definition: FullName.cpp:12
std::string GetNameStock(const std::string &frame_name)
Extract the stock name from a frame name.
Definition: FullName.cpp:116
ETime GetTimeScale(const std::string &frame_name)
Extract the TimeScale from a frame name.
Definition: FullName.cpp:122
Group general functions to convert to/from string, split line...
Namespace's for functions related to the string format of Indicator / Frame.
std::string GetNameStock(const std::string &fname)
Extract the name of the stock.
Definition: FullName.cpp:46
static Indicator GetIndicator(const std::string &str_name)
Constructor with a string label.
Definition: Indicator.cpp:234
Indicator GetIndicator(const std::string &fname)
Extract the Indicator from a fullname.
Definition: FullName.cpp:59
Indicator GetIndicator(const std::string &sname)
Extract the indicator from a frame name.
Definition: FullName.cpp:103
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
Definition: TimeScale.h:48
std::string GetFrameName(const std::string &fname)
Extract NameStock_Timescale (FrameName) from a fullname.
Definition: FullName.cpp:92
std::string GetShortName(const std::string &fname)
Extract Indicator_params (string) from a fullname.
Definition: FullName.cpp:78
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
std::string MakeShortName(const Indicator &indic, const std::vector< int > &param)
Create a short name from its components.
Definition: FullName.cpp:109
void splitline(const std::string &str, const std::string &delimiters, std::vector< std::string > &tokens)
splitline
Definition: Utils.cpp:56
std::vector< int > GetParams(const std::string &fname)
Extract params from a fullname.
Definition: FullName.cpp:65
std::string const label() const
Get the label.
Definition: Indicator.cpp:51
ETime GetTimeScale(const std::string &fname)
Extract the TimeScale from a fullname.
Definition: FullName.cpp:53