15 #ifndef TSA_FUNCTOR_PARENT__INCLUDED 16 #define TSA_FUNCTOR_PARENT__INCLUDED 21 #include "TSASeriesTemplate.h" 22 #include "TSAString.h" 23 #include "TSASeriesVariant.h" 24 #include "TSASeriesImp.h" 25 #include "TSAFunctions.h" 26 #include "TSAStrategy.h" 27 #include "TSAFunctorParent.h" 33 strategy* m_strategy_ptr =
nullptr;
35 bool first_bar_completed(
void)
const {
return m_first_bar_is_completed; }
36 void set_first_bar_completed(
void) { m_first_bar_is_completed =
true; }
37 bool m_first_bar_is_completed =
false;
39 functor_parent_base(
void) { ; }
40 virtual ~functor_parent_base(
void){ ; }
41 virtual bool input_data_is_ok(
void) {
return true; }
42 virtual void evaluate(
void) { ; };
43 void set_strategy_ptr(strategy* ptr) { m_strategy_ptr = ptr; }
44 strategy* strategy_ptr(
void)
const {
return m_strategy_ptr; }
54 class parent :
public functor_parent_base {
57 bool m_out_series_has_data =
false;
61 std::vector<h_line> m_h_lines;
70 std::vector<plot_info> m_plots;
72 std::vector<series<T>*> m_outputs;
73 date_time m_last_update_timestamp;
76 void check_for_duplicate_invocation(
void);
78 void create_outputs(
size_t num_outputs);
79 void verify_class_member_declaration(
void)
const;
84 parent(
size_t num_outputs);
86 virtual ~parent(
void);
88 operator variant(
void)
const;
90 operator series<T>& (void)
const;
92 operator series_cref<T> (void)
const;
94 series_cref<T> output(
size_t position)
const;
98 void push(
size_t position, T value);
100 operator T(
void)
const;
104 T value(
size_t position)
const;
106 size_t output_count(
void)
const;
109 void add_h_line(
const h_line& _l);
111 void add_h_line(
double _y_value,
const color& _color,
int _weight);
113 void add_plot(
const plot_info& _p);
115 plot_info& get_plot_info(
size_t pos);
117 const plot_info& get_plot_info(
size_t pos)
const;
122 void parent<T>::check_for_duplicate_invocation(
void) {
124 date_time strategy_timestamp = strategy_context::strategy_ptr()->bar_timestamp();
125 if(strategy_timestamp == parent<T>::m_last_update_timestamp)
126 throw exception(
this,
"functor invoked twice on same strategy during_bar; timestamp: " 127 + strategy_timestamp.to_string(),
SLOC);
128 parent<T>::m_last_update_timestamp = strategy_timestamp;
133 void parent<T>::create_outputs(
size_t num_outputs) {
134 for(
size_t c = 0; c < num_outputs; c++) {
135 auto ptr =
new series<T>(
this);
136 tsa_assert(ptr->owning_functor_ptr() ==
this);
137 tsa_assert(!ptr->is_managed());
138 m_outputs.push_back(ptr);
139 m_plots.push_back(plot_info());
144 parent<T>::parent(
void) {
145 verify_class_member_declaration();
150 parent<T>::parent(
size_t num_outputs) {
151 verify_class_member_declaration();
152 create_outputs(num_outputs);
156 void parent<T>::verify_class_member_declaration(
void)
const {
157 strategy* strat_ptr = strategy_context::strategy_ptr(
true);
159 throw tsa::exception(
this,
"'Managed functions' must be invoked as part of strategy::on_prepare(). " 160 " 'Functor objects' must be declared as strategy class members!",
SLOC);
165 parent<T>::~parent(
void) {
166 for(
auto& ptr : m_outputs) {
172 parent<T>::operator series<T>& (void)
const {
173 return *m_outputs[0];
177 parent<T>::operator series_cref<T> (void)
const {
178 return series_cref<T>(*m_outputs[0]);
182 parent<T>::operator variant(
void)
const {
187 series_cref<T> parent<T>::output(
size_t position)
const {
188 series<T>* ser_ptr = m_outputs[position];
189 tsa_assert(ser_ptr->owning_functor_ptr() ==
this);
190 return series_cref<T>(*m_outputs[position]);
194 void parent<T>::push(T value) {
195 m_outputs[0]->push(value);
196 m_out_series_has_data =
true;
200 void parent<T>::push(
size_t position, T value) {
201 m_outputs[position]->push(value);
202 m_out_series_has_data =
true;
206 parent<T>::operator T(
void)
const {
211 T parent<T>::value(
void)
const {
213 if(!m_out_series_has_data || m_outputs[0]->size() == 0) {
217 return m_outputs[0]->get_at(0);
221 T parent<T>::value(
size_t position)
const {
223 if(!m_out_series_has_data || m_outputs[0]->size() == 0) {
224 throw tsa::exception(class_name(),
"no output value available; was functor invoked?",
SLOC);
227 return m_outputs[position]->get_at(0);
231 size_t parent<T>::output_count(
void)
const {
return m_outputs.size(); }
234 void parent<T>::add_h_line(
const h_line& _l) { m_h_lines.push_back(_l); }
237 void parent<T>::add_h_line(
double _y_value,
const color& _color,
int _weight) {
239 l.y_value = _y_value;
242 m_h_lines.push_back(l);
245 void parent<T>::add_plot(
const plot_info& _p) { m_plots.push_back(_p); }
248 plot_info& parent<T>::get_plot_info(
size_t pos) {
return m_plots[pos]; }
251 const plot_info& parent<T>::get_plot_info(
size_t pos)
const {
return m_plots[pos]; }
267 h_line(
void) : clr(
color(200, 200, 200)), y_value(0.0), weight(1) { ; }
268 h_line(
const color& _color,
double _y_value,
int _weight)
269 : clr(_color), y_value(_y_value), weight(_weight) {
273 typedef std::vector<h_line> HLINEARR;
289 double get_value(
void) {
292 void set_value(
double _v) {
295 plot_info(
void) { ; }
297 typedef std::vector<plot_info> PLOTARR;
301 void add_h_line(
const h_line& _l) { m_h_lines.push_back(_l); }
302 void add_h_line(
double _y_value,
const color& _color,
int _weight) {
304 l.y_value = _y_value;
307 m_h_lines.push_back(l);
309 void add_plot(
const plot_info& _p) { m_plots.push_back(_p); }
310 plot_info& get_plot(
size_t pos) {
return m_plots[pos]; }
311 const plot_info& get_plot(
size_t pos)
const {
return m_plots[pos]; }
312 size_t plot_count(
void)
const {
return m_plots.size(); }
Namespace for the 'Trading System API' library.
Definition: original1.TSA3Core.cpp:20
#define SLOC
Macro to be passed as argument to Exception constructors. Contains information about the source locat...
Definition: TSAError.h:92
plot_type
Values that represent plot types.
Definition: TSASeriesTemplate.h:149
Parent class.
Definition: TSAFunctorParent.h:260
variant objects can represent values of different types.
Definition: TSAVariant.h:140
Class tsa::exception used by most classes of the Trading System API library. The class inherits from ...
Definition: TSAError.h:37
Parent class for many library classes.
Definition: TSATypeDef.h:462
Represents a color for use in graphics operations.
Definition: TSATypeDef.h:1041