OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
script_info.hpp
Go to the documentation of this file.
1#pragma once
2
11
12#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 201703L
13#error \
14 "OpenPine C++ wrapper headers require C++17 (std::optional, std::string_view)."
15#endif
16
17#include <optional>
18#include <string_view>
19
20#include "ffi.hpp"
21#include "script_input.hpp"
22#include "string_ref.hpp"
23#include "types.hpp"
24
25namespace openpine {
26
34 private:
35 const ffi::ScriptInfo* p_;
36
37 public:
38 ScriptInfo(const ffi::ScriptInfo* p) : p_(p) {}
39
44 bool overlay() const { return ffi::scriptInfoOverlay(p_); }
45
50 ScriptTypeKind scriptType() const { return ffi::scriptInfoScriptType(p_); }
51
56 std::optional<std::string_view> title() const {
57 ffi::PineStringRef ref{};
58 if (ffi::scriptInfoTitle(p_, &ref)) {
59 return detail::refToView(ref);
60 }
61 return std::nullopt;
62 }
63
69 std::optional<Indicator> indicator() const {
70 Indicator out{};
71 if (ffi::scriptInfoIndicator(p_, &out)) return out;
72 return std::nullopt;
73 }
74
78 std::optional<Library> library() const {
79 Library out{};
80 if (ffi::scriptInfoLibrary(p_, &out)) return out;
81 return std::nullopt;
82 }
83
89 std::optional<Strategy> strategy() const {
90 Strategy out{};
91 if (ffi::scriptInfoStrategy(p_, &out)) return out;
92 return std::nullopt;
93 }
94
98 uintptr_t inputsLength() const { return ffi::scriptInfoInputsLength(p_); }
99
103 std::optional<ScriptInput> inputAt(uintptr_t index) const {
104 const ffi::Input* inp = ffi::scriptInfoInput(p_, index);
105 if (inp) return ScriptInput{inp};
106 return std::nullopt;
107 }
108
112 uintptr_t alertConditionsLength() const {
113 return ffi::scriptInfoAlertConditionsLength(p_);
114 }
115
119 std::optional<std::string_view> alertConditionTitle(uintptr_t index) const {
120 ffi::PineStringRef ref{};
121 if (!ffi::scriptInfoAlertConditionTitle(p_, index, &ref))
122 return std::nullopt;
123 return detail::optRefToView(ref.data != nullptr, ref);
124 }
125
129 std::optional<std::string_view> alertConditionMessage(uintptr_t index) const {
130 ffi::PineStringRef ref{};
131 if (!ffi::scriptInfoAlertConditionMessage(p_, index, &ref))
132 return std::nullopt;
133 return detail::optRefToView(ref.data != nullptr, ref);
134 }
135};
136
137} // namespace openpine
uintptr_t alertConditionsLength() const
Number of declared alert conditions.
ScriptInfo(const ffi::ScriptInfo *p)
uintptr_t inputsLength() const
Number of declared user inputs.
bool overlay() const
Whether the script is drawn on the price chart.
std::optional< std::string_view > alertConditionMessage(uintptr_t index) const
Alert condition message at the given index.
std::optional< std::string_view > alertConditionTitle(uintptr_t index) const
Alert condition title at the given index.
std::optional< Indicator > indicator() const
Full indicator payload. Only defined when scriptType() == Indicator. String refs inside the struct ar...
ScriptTypeKind scriptType() const
Script type discriminant.
std::optional< std::string_view > title() const
Script title if present.
std::optional< Strategy > strategy() const
Full strategy payload. Only defined when scriptType() == Strategy. String refs inside the struct are ...
std::optional< ScriptInput > inputAt(uintptr_t index) const
Input at the given index, or nullopt if index is out of range.
std::optional< Library > library() const
Full library payload. Only defined when scriptType() == Library.
Wrapper for a single script input (borrowed from ScriptInfo).
std::optional< std::string_view > optRefToView(bool has_field, const ffi::PineStringRef &ref)
Returns optional string_view when has_field is true, otherwise std::nullopt.
std::string_view refToView(const ffi::PineStringRef &ref)
C++ wrapper for a single script input (ScriptInput) from the OpenPine VM.
Shared helpers for converting C ABI string refs to std::string_view.
Re-exports FFI types into the openpine namespace.