OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
plot_shape.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 <optional>
15#include <string_view>
16
17#include "../display.hpp"
18#include "../ffi.hpp"
19#include "../string_ref.hpp"
20
21namespace openpine {
22namespace seriesgraph {
23
27class PlotShape {
28 private:
29 const ffi::PlotShape* p_;
30
31 public:
32 PlotShape(const ffi::PlotShape* p) : p_(p) {}
33
38 std::optional<std::string_view> title() const {
39 ffi::PineStringRef ref;
40 if (ffi::plotShapeTitle(p_, &ref)) {
41 return detail::refToView(ref);
42 } else {
43 return std::nullopt;
44 }
45 }
46
50 std::optional<double> value(uintptr_t idx) const {
51 double v;
52 if (ffi::plotShapeValue(p_, idx, &v)) {
53 return v;
54 } else {
55 return std::nullopt;
56 }
57 }
58
62 std::optional<bool> boolValue(uintptr_t idx) const {
63 bool v;
64 if (ffi::plotShapeBoolValue(p_, idx, &v)) {
65 return v;
66 } else {
67 return std::nullopt;
68 }
69 }
70
74 ffi::Shape style() const { return ffi::plotShapeStyle(p_); }
75
79 ffi::Location location() const { return ffi::plotShapeLocation(p_); }
80
84 std::optional<uint32_t> color(uintptr_t idx) const {
85 uint32_t col;
86 if (ffi::plotShapeColor(p_, idx, &col)) {
87 return col;
88 } else {
89 return std::nullopt;
90 }
91 }
92
96 int32_t offset() const { return ffi::plotShapeOffset(p_); }
97
101 std::optional<std::string_view> text() const {
102 ffi::PineStringRef ref;
103 if (ffi::plotShapeText(p_, &ref)) {
104 return detail::refToView(ref);
105 } else {
106 return std::nullopt;
107 }
108 }
109
113 std::optional<uint32_t> textColor(uintptr_t idx) const {
114 uint32_t col;
115 if (ffi::plotShapeTextColor(p_, idx, &col)) {
116 return col;
117 } else {
118 return std::nullopt;
119 }
120 }
121
125 bool editable() const { return ffi::plotShapeEditable(p_); }
126
130 ffi::Size size() const { return ffi::plotShapeSize(p_); }
131
135 std::optional<uintptr_t> showLast() const {
136 uintptr_t v;
137 if (ffi::plotShapeShowLast(p_, &v)) {
138 return v;
139 } else {
140 return std::nullopt;
141 }
142 }
143
147 Display display() const { return Display(ffi::plotShapeDisplay(p_)); }
148
152 std::optional<std::string_view> format() const {
153 ffi::PineStringRef ref;
154 if (ffi::plotShapeFormat(p_, &ref)) {
155 return detail::refToView(ref);
156 } else {
157 return std::nullopt;
158 }
159 }
160
164 std::optional<int32_t> precision() const {
165 int32_t v;
166 if (ffi::plotShapePrecision(p_, &v)) {
167 return v;
168 } else {
169 return std::nullopt;
170 }
171 }
172
176 bool forceOverlay() const { return ffi::plotShapeForceOverlay(p_); }
177};
178
179} // namespace seriesgraph
180} // namespace openpine
A type-safe display bitmask.
Definition display.hpp:25
bool editable() const
Returns whether the plot-shape is editable.
std::optional< std::string_view > format() const
Gets the optional formatting hint.
ffi::Shape style() const
Gets the shape style.
std::optional< int32_t > precision() const
Gets the optional decimal precision.
std::optional< bool > boolValue(uintptr_t idx) const
Gets the series value at the specified index interpreted as boolean.
Display display() const
Gets the display bitmask.
int32_t offset() const
Gets the bar index offset.
std::optional< std::string_view > text() const
Gets the optional text string.
std::optional< std::string_view > title() const
Gets the title.
std::optional< uint32_t > color(uintptr_t idx) const
Gets the per-bar color.
std::optional< double > value(uintptr_t idx) const
Gets the series numeric value at the specified index.
std::optional< uint32_t > textColor(uintptr_t idx) const
Gets the per-bar text color.
bool forceOverlay() const
Gets whether the plot-shape is forced to render as overlay.
ffi::Size size() const
Gets the shape size.
std::optional< uintptr_t > showLast() const
Gets the show_last value, if set.
ffi::Location location() const
Gets the placement location.
PlotShape(const ffi::PlotShape *p)
Type-safe wrappers for display bitmasks used by visuals.
std::string_view refToView(const ffi::PineStringRef &ref)
Shared helpers for converting C ABI string refs to std::string_view.