OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
plot_char.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 PlotChar {
28 private:
29 const ffi::PlotChar* p_;
30
31 public:
32 PlotChar(const ffi::PlotChar* p) : p_(p) {}
33
38 std::optional<std::string_view> title() const {
39 ffi::PineStringRef ref;
40 if (ffi::plotCharTitle(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::plotCharValue(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::plotCharBoolValue(p_, idx, &v)) {
65 return v;
66 } else {
67 return std::nullopt;
68 }
69 }
70
74 char32_t character() const {
75 return static_cast<char32_t>(ffi::plotCharChar(p_));
76 }
77
81 ffi::Location location() const { return ffi::plotCharLocation(p_); }
82
86 std::optional<uint32_t> color(uintptr_t idx) const {
87 uint32_t col;
88 if (ffi::plotCharColor(p_, idx, &col)) {
89 return col;
90 } else {
91 return std::nullopt;
92 }
93 }
94
98 int32_t offset() const { return ffi::plotCharOffset(p_); }
99
103 std::optional<std::string_view> text() const {
104 ffi::PineStringRef ref;
105 if (ffi::plotCharText(p_, &ref)) {
106 return detail::refToView(ref);
107 } else {
108 return std::nullopt;
109 }
110 }
111
115 std::optional<uint32_t> textColor(uintptr_t idx) const {
116 uint32_t col;
117 if (ffi::plotCharTextColor(p_, idx, &col)) {
118 return col;
119 } else {
120 return std::nullopt;
121 }
122 }
123
127 bool editable() const { return ffi::plotCharEditable(p_); }
128
132 ffi::Size size() const { return ffi::plotCharSize(p_); }
133
137 std::optional<uintptr_t> showLast() const {
138 uintptr_t v;
139 if (ffi::plotCharShowLast(p_, &v)) {
140 return v;
141 } else {
142 return std::nullopt;
143 }
144 }
145
149 Display display() const { return Display(ffi::plotCharDisplay(p_)); }
150
154 std::optional<std::string_view> format() const {
155 ffi::PineStringRef ref;
156 if (ffi::plotCharFormat(p_, &ref)) {
157 return detail::refToView(ref);
158 } else {
159 return std::nullopt;
160 }
161 }
162
166 std::optional<int32_t> precision() const {
167 int32_t v;
168 if (ffi::plotCharPrecision(p_, &v)) {
169 return v;
170 } else {
171 return std::nullopt;
172 }
173 }
174
178 bool forceOverlay() const { return ffi::plotCharForceOverlay(p_); }
179};
180
181} // namespace seriesgraph
182} // namespace openpine
A type-safe display bitmask.
Definition display.hpp:25
std::optional< bool > boolValue(uintptr_t idx) const
Gets the series value at the specified index interpreted as boolean.
Definition plot_char.hpp:62
bool editable() const
Returns whether the plot-char is editable.
std::optional< std::string_view > text() const
Gets the optional text string.
int32_t offset() const
Gets the bar index offset.
Definition plot_char.hpp:98
ffi::Location location() const
Gets the placement location.
Definition plot_char.hpp:81
Display display() const
Gets the display bitmask.
std::optional< uint32_t > textColor(uintptr_t idx) const
Gets the per-bar text color.
std::optional< int32_t > precision() const
Gets the optional decimal precision.
std::optional< std::string_view > title() const
Gets the title.
Definition plot_char.hpp:38
bool forceOverlay() const
Gets whether the plot-char is forced to render as overlay.
std::optional< uint32_t > color(uintptr_t idx) const
Gets the per-bar color.
Definition plot_char.hpp:86
char32_t character() const
Gets the character codepoint.
Definition plot_char.hpp:74
std::optional< double > value(uintptr_t idx) const
Gets the series numeric value at the specified index.
Definition plot_char.hpp:50
std::optional< uintptr_t > showLast() const
Gets the show_last value, if set.
std::optional< std::string_view > format() const
Gets the optional formatting hint.
PlotChar(const ffi::PlotChar *p)
Definition plot_char.hpp:32
ffi::Size size() const
Gets the character size.
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.