OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
series_graph.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 201703L
9#error \
10 "OpenPine C++ wrapper headers require C++17 (std::optional, std::string_view)."
11#endif
12
13#include <cstdint>
14#include <memory>
15#include <optional>
16
17#include "../ffi.hpp"
18#include "../types.hpp"
19#include "background_colors.hpp"
20#include "fill.hpp"
21#include "plot.hpp"
22#include "plot_arrow.hpp"
23#include "plot_bar.hpp"
24#include "plot_candle.hpp"
25#include "plot_char.hpp"
26#include "plot_shape.hpp"
27
28namespace openpine {
29
38 private:
39 const ffi::SeriesGraph* p_;
40
41 public:
43 SeriesGraph(const ffi::SeriesGraph* p) : p_(p) {}
44
49 SeriesGraphType type() const { return ffi::seriesGraphType(p_); }
50
56 std::optional<seriesgraph::Plot> asPlot() const {
57 const ffi::Plot* plot_ptr = ffi::seriesGraphPlot(p_);
58 if (plot_ptr) {
59 return seriesgraph::Plot{plot_ptr};
60 } else {
61 return std::nullopt;
62 }
63 }
64
70 std::optional<seriesgraph::BackgroundColors> asBackgroundColors() const {
71 const ffi::BackgroundColors* p = ffi::seriesGraphBackgroundColors(p_);
72 if (p) {
74 } else {
75 return std::nullopt;
76 }
77 }
78
84 std::optional<seriesgraph::Fill> asFill() const {
85 const ffi::Fill* p = ffi::seriesGraphFill(p_);
86 if (p) {
87 return seriesgraph::Fill{p};
88 } else {
89 return std::nullopt;
90 }
91 }
92
98 std::optional<seriesgraph::PlotArrow> asPlotArrow() const {
99 const ffi::PlotArrow* p = ffi::seriesGraphPlotArrow(p_);
100 if (p) {
101 return seriesgraph::PlotArrow{p};
102 } else {
103 return std::nullopt;
104 }
105 }
106
112 std::optional<seriesgraph::PlotBar> asPlotBar() const {
113 const ffi::PlotBar* p = ffi::seriesGraphPlotBar(p_);
114 if (p) {
115 return seriesgraph::PlotBar{p};
116 } else {
117 return std::nullopt;
118 }
119 }
120
126 std::optional<seriesgraph::PlotCandle> asPlotCandle() const {
127 const ffi::PlotCandle* p = ffi::seriesGraphPlotCandle(p_);
128 if (p) {
129 return seriesgraph::PlotCandle{p};
130 } else {
131 return std::nullopt;
132 }
133 }
134
140 std::optional<seriesgraph::PlotChar> asPlotChar() const {
141 const ffi::PlotChar* p = ffi::seriesGraphPlotChar(p_);
142 if (p) {
143 return seriesgraph::PlotChar{p};
144 } else {
145 return std::nullopt;
146 }
147 }
148
154 std::optional<seriesgraph::PlotShape> asPlotShape() const {
155 const ffi::PlotShape* p = ffi::seriesGraphPlotShape(p_);
156 if (p) {
157 return seriesgraph::PlotShape{p};
158 } else {
159 return std::nullopt;
160 }
161 }
162};
163
171 private:
172 std::unique_ptr<ffi::CSeriesGraphIterator,
173 decltype(&ffi::seriesGraphIteratorDelete)>
174 p_;
175 std::optional<ffi::SeriesGraphType> type_filter_;
176 int64_t id_;
177 const ffi::SeriesGraph* graph_;
178
179 public:
185 SeriesGraphIterator(ffi::CSeriesGraphIterator* p,
186 std::optional<ffi::SeriesGraphType> type = std::nullopt)
187 : p_(p, ffi::seriesGraphIteratorDelete), type_filter_(type) {}
188
194 bool next() {
195 while (ffi::seriesGraphIteratorNext(p_.get(), &id_, &graph_)) {
196 if (!type_filter_.has_value() ||
197 ffi::seriesGraphType(graph_) == *type_filter_) {
198 return true;
199 }
200 }
201 return false;
202 }
203
207 int64_t id() const { return id_; }
208
212 SeriesGraph seriesGraph() const { return SeriesGraph{graph_}; }
213};
214
215} // namespace openpine
C++ wrapper for background-colors visual output.
Represents a series graph in a chart.
SeriesGraph(const ffi::SeriesGraph *p)
Constructs a wrapper around the given series graph pointer.
std::optional< seriesgraph::PlotCandle > asPlotCandle() const
Gets the plot-candle associated with this graph, if any.
std::optional< seriesgraph::PlotBar > asPlotBar() const
Gets the plot-bar associated with this graph, if any.
std::optional< seriesgraph::Plot > asPlot() const
Gets the plot associated with this graph, if any.
std::optional< seriesgraph::BackgroundColors > asBackgroundColors() const
Gets the background-colors associated with this graph, if any.
std::optional< seriesgraph::PlotChar > asPlotChar() const
Gets the plot-char associated with this graph, if any.
SeriesGraphType type() const
Gets the type of the series graph.
std::optional< seriesgraph::Fill > asFill() const
Gets the fill associated with this graph, if any.
std::optional< seriesgraph::PlotArrow > asPlotArrow() const
Gets the plot-arrow associated with this graph, if any.
std::optional< seriesgraph::PlotShape > asPlotShape() const
Gets the plot-shape associated with this graph, if any.
bool next()
Advances the iterator to the next series graph (respecting type filter if set).
int64_t id() const
Gets the ID of the current series graph.
SeriesGraph seriesGraph() const
Gets the current series graph.
SeriesGraphIterator(ffi::CSeriesGraphIterator *p, std::optional< ffi::SeriesGraphType > type=std::nullopt)
Constructs an iterator from the C ABI handle.
Represents background-colors settings in a chart.
Represents a fill between two anchors.
Definition fill.hpp:28
Represents a plotarrow output.
Represents a plotbar output.
Definition plot_bar.hpp:27
Represents a plotcandle output.
Represents a plotchar output.
Definition plot_char.hpp:27
Represents a plot graph in a chart.
Definition plot.hpp:30
Represents a plotshape output.
C++ wrapper for fill visual output.
C++ wrapper for plot visual output.
C++ wrapper for plot-arrow visual output.
C++ wrapper for plot-bar visual output.
C++ wrapper for plot-candle visual output.
C++ wrapper for plot-char visual output.
C++ wrapper for plot-shape visual output.
Re-exports FFI types into the openpine namespace.