OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
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 "box.hpp"
20#include "hline.hpp"
21#include "label.hpp"
22#include "line.hpp"
23#include "line_fill.hpp"
24#include "polyline.hpp"
25#include "table.hpp"
26
27namespace openpine {
28
36class Graph {
37 private:
38 const ffi::Graph* p_;
39
40 public:
42 Graph(const ffi::Graph* p) : p_(p) {}
43
48 GraphType type() const { return ffi::graphType(p_); }
49
55 std::optional<graph::Hline> asHline() const {
56 const ffi::Hline* p = ffi::graphHline(p_);
57 if (p) {
58 return graph::Hline{p};
59 }
60 return std::nullopt;
61 }
62
68 std::optional<graph::Label> asLabel() const {
69 const ffi::Label* p = ffi::graphLabel(p_);
70 if (p) {
71 return graph::Label{p};
72 }
73 return std::nullopt;
74 }
75
81 std::optional<graph::Line> asLine() const {
82 const ffi::Line* p = ffi::graphLine(p_);
83 if (p) {
84 return graph::Line{p};
85 }
86 return std::nullopt;
87 }
88
94 std::optional<graph::LineFill> asLineFill() const {
95 const ffi::LineFill* p = ffi::graphLineFill(p_);
96 if (p) {
97 return graph::LineFill{p};
98 }
99 return std::nullopt;
100 }
101
107 std::optional<graph::Box> asBox() const {
108 const ffi::Box* p = ffi::graphBox(p_);
109 if (p) {
110 return graph::Box{p};
111 }
112 return std::nullopt;
113 }
114
120 std::optional<graph::Polyline> asPolyline() const {
121 const ffi::Polyline* p = ffi::graphPolyline(p_);
122 if (p) {
123 return graph::Polyline{p};
124 }
125 return std::nullopt;
126 }
127
133 std::optional<graph::Table> asTable() const {
134 const ffi::Table* p = ffi::graphTable(p_);
135 if (p) {
136 return graph::Table{p};
137 }
138 return std::nullopt;
139 }
140};
141
149 private:
150 std::unique_ptr<ffi::CGraphIterator, decltype(&ffi::graphIteratorDelete)> p_;
151 std::optional<ffi::GraphType> type_filter_;
152 int64_t id_;
153 const ffi::Graph* graph_;
154
155 public:
161 GraphIterator(ffi::CGraphIterator* p,
162 std::optional<ffi::GraphType> type = std::nullopt)
163 : p_(p, ffi::graphIteratorDelete), type_filter_(type) {}
164
169 bool next() {
170 while (ffi::graphIteratorNext(p_.get(), &id_, &graph_)) {
171 if (!type_filter_.has_value() ||
172 ffi::graphType(graph_) == *type_filter_) {
173 return true;
174 }
175 }
176 return false;
177 }
178
180 int64_t id() const { return id_; }
181
183 Graph graph() const { return Graph{graph_}; }
184};
185
186} // namespace openpine
C++ wrapper for box output.
Represents a non-series graph in a chart.
Definition graph.hpp:36
std::optional< graph::Line > asLine() const
Gets the line payload, if this graph is a line.
Definition graph.hpp:81
std::optional< graph::Hline > asHline() const
Gets the hline payload, if this graph is an hline.
Definition graph.hpp:55
std::optional< graph::Polyline > asPolyline() const
Gets the polyline payload, if this graph is a polyline.
Definition graph.hpp:120
GraphType type() const
Gets the type of the graph.
Definition graph.hpp:48
Graph(const ffi::Graph *p)
Constructs a Graph wrapper around the given pointer.
Definition graph.hpp:42
std::optional< graph::Table > asTable() const
Gets the table payload, if this graph is a table.
Definition graph.hpp:133
std::optional< graph::Label > asLabel() const
Gets the label payload, if this graph is a label.
Definition graph.hpp:68
std::optional< graph::Box > asBox() const
Gets the box payload, if this graph is a box.
Definition graph.hpp:107
std::optional< graph::LineFill > asLineFill() const
Gets the line-fill payload, if this graph is a line fill.
Definition graph.hpp:94
int64_t id() const
Returns the ID of the current graph.
Definition graph.hpp:180
bool next()
Advances to the next graph (respecting type filter if set).
Definition graph.hpp:169
GraphIterator(ffi::CGraphIterator *p, std::optional< ffi::GraphType > type=std::nullopt)
Constructs an iterator from the C ABI handle.
Definition graph.hpp:161
Graph graph() const
Returns the current graph.
Definition graph.hpp:183
Represents a box graph.
Definition box.hpp:27
Represents a horizontal-line (hline) graph.
Definition hline.hpp:28
Represents a label graph.
Definition label.hpp:27
Represents a line-fill graph.
Definition line_fill.hpp:24
Represents a line graph.
Definition line.hpp:25
Represents a polyline graph.
Definition polyline.hpp:25
Represents a table graph.
Definition table.hpp:127
C++ wrapper for horizontal-line (hline) output.
C++ wrapper for label output.
C++ wrapper for line output.
C++ wrapper for line-fill output.
C++ wrapper for polyline output.
C++ wrapper for table output.
Re-exports FFI types into the openpine namespace.