OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
input_enum.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 201703L
9#error "OpenPine C++ wrapper headers require C++17."
10#endif
11
12#include <optional>
13#include <string_view>
14
15#include "../ffi.hpp"
16#include "../string_ref.hpp"
17#include "../types.hpp"
18
19namespace openpine {
20namespace inputs {
21
24 int64_t value;
25 std::string_view title;
26};
27
33class InputEnum {
34 public:
36 InputEnum(const ffi::InputEnum& data, const ffi::Input* input = nullptr)
37 : data_(data), input_(input) {}
38
39 int64_t id() const { return data_.id; }
41 uintptr_t enumTypeId() const { return data_.enum_typeid; }
43 int64_t defaultValue() const { return data_.default_value; }
45 std::optional<std::string_view> title() const {
46 return detail::optRefToView(data_.has_title, data_.title);
47 }
48
49 std::optional<std::string_view> tooltip() const {
50 return detail::optRefToView(data_.has_tooltip, data_.tooltip);
51 }
52
53 std::optional<std::string_view> inlineGroup() const {
54 return detail::optRefToView(data_.has_inline, data_.inline_);
55 }
56
57 std::optional<std::string_view> group() const {
58 return detail::optRefToView(data_.has_group, data_.group);
59 }
60
61 uint64_t display() const { return data_.display; }
63 bool active() const { return data_.active; }
65 uintptr_t optionsLength() const { return data_.options_length; }
67 bool confirm() const { return data_.confirm; }
74 std::optional<InputEnumOptionView> optionAt(uintptr_t index) const {
75 if (!input_) return std::nullopt;
76 ffi::InputEnumOption opt{};
77 if (!ffi::inputEnumOptionAt(input_, index, &opt)) return std::nullopt;
78 return InputEnumOptionView{opt.value, detail::refToView(opt.title)};
79 }
80
81 private:
82 ffi::InputEnum data_;
83 const ffi::Input* input_ = nullptr;
85};
86
87} // namespace inputs
88} // namespace openpine
Wrapper for a single script input (borrowed from ScriptInfo).
uint64_t display() const
Display bitmask.
bool active() const
Whether the input is active.
std::optional< InputEnumOptionView > optionAt(uintptr_t index) const
Option at the given index (value + title).
uintptr_t optionsLength() const
Number of options (for optionAt()).
InputEnum(const ffi::InputEnum &data, const ffi::Input *input=nullptr)
Constructs from FFI data and optional handle for optionAt().
int64_t id() const
Input ID.
bool confirm() const
Whether the input requires confirmation.
int64_t defaultValue() const
Default value (option index).
std::optional< std::string_view > tooltip() const
Optional tooltip.
std::optional< std::string_view > group() const
Optional group name.
std::optional< std::string_view > inlineGroup() const
Optional inline group name.
uintptr_t enumTypeId() const
Enum type identifier.
std::optional< std::string_view > title() const
Optional title.
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)
Shared helpers for converting C ABI string refs to std::string_view.
One option (value + title) in an enum input.
Re-exports FFI types into the openpine namespace.