OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
plot_bar.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 PlotBar {
28 private:
29 const ffi::PlotBar* p_;
30
31 public:
32 PlotBar(const ffi::PlotBar* p) : p_(p) {}
33
38 std::optional<std::string_view> title() const {
39 ffi::PineStringRef ref;
40 if (ffi::plotBarTitle(p_, &ref)) {
41 return detail::refToView(ref);
42 } else {
43 return std::nullopt;
44 }
45 }
46
50 std::optional<ffi::Bar> value(uintptr_t idx) const {
51 ffi::Bar v;
52 if (ffi::plotBarValue(p_, idx, &v)) {
53 return v;
54 } else {
55 return std::nullopt;
56 }
57 }
58
62 std::optional<uint32_t> color(uintptr_t idx) const {
63 uint32_t col;
64 if (ffi::plotBarColor(p_, idx, &col)) {
65 return col;
66 } else {
67 return std::nullopt;
68 }
69 }
70
74 bool editable() const { return ffi::plotBarEditable(p_); }
75
79 std::optional<uintptr_t> showLast() const {
80 uintptr_t v;
81 if (ffi::plotBarShowLast(p_, &v)) {
82 return v;
83 } else {
84 return std::nullopt;
85 }
86 }
87
91 Display display() const { return Display(ffi::plotBarDisplay(p_)); }
92
96 std::optional<std::string_view> format() const {
97 ffi::PineStringRef ref;
98 if (ffi::plotBarFormat(p_, &ref)) {
99 return detail::refToView(ref);
100 } else {
101 return std::nullopt;
102 }
103 }
104
108 std::optional<int32_t> precision() const {
109 int32_t v;
110 if (ffi::plotBarPrecision(p_, &v)) {
111 return v;
112 } else {
113 return std::nullopt;
114 }
115 }
116
120 bool forceOverlay() const { return ffi::plotBarForceOverlay(p_); }
121};
122
123} // namespace seriesgraph
124} // namespace openpine
A type-safe display bitmask.
Definition display.hpp:25
bool forceOverlay() const
Gets whether the plot-bar is forced to render as overlay.
Definition plot_bar.hpp:120
std::optional< int32_t > precision() const
Gets the optional decimal precision.
Definition plot_bar.hpp:108
std::optional< ffi::Bar > value(uintptr_t idx) const
Gets the OHLC bar at the specified index.
Definition plot_bar.hpp:50
std::optional< uintptr_t > showLast() const
Gets the show_last value, if set.
Definition plot_bar.hpp:79
std::optional< uint32_t > color(uintptr_t idx) const
Gets the color at the specified index.
Definition plot_bar.hpp:62
Display display() const
Gets the display bitmask.
Definition plot_bar.hpp:91
PlotBar(const ffi::PlotBar *p)
Definition plot_bar.hpp:32
bool editable() const
Returns whether the plot-bar is editable.
Definition plot_bar.hpp:74
std::optional< std::string_view > title() const
Gets the title.
Definition plot_bar.hpp:38
std::optional< std::string_view > format() const
Gets the optional formatting hint.
Definition plot_bar.hpp:96
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.