OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
input_int.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
27class InputInt {
28 public:
30 InputInt(const ffi::InputInt& data, const ffi::Input* input = nullptr)
31 : data_(data), input_(input) {}
32
33 int64_t id() const { return data_.id; }
35 int64_t defaultValue() const { return data_.default_value; }
37 std::optional<std::string_view> title() const {
38 return detail::optRefToView(data_.has_title, data_.title);
39 }
40
41 std::optional<std::string_view> tooltip() const {
42 return detail::optRefToView(data_.has_tooltip, data_.tooltip);
43 }
44
45 std::optional<std::string_view> inlineGroup() const {
46 return detail::optRefToView(data_.has_inline, data_.inline_);
47 }
48
49 std::optional<std::string_view> group() const {
50 return detail::optRefToView(data_.has_group, data_.group);
51 }
52
53 uint64_t display() const { return data_.display; }
55 bool active() const { return data_.active; }
57 uintptr_t optionsLength() const { return data_.options_length; }
59 std::optional<int64_t> minValue() const {
60 return data_.has_min_value ? std::optional(data_.min_value) : std::nullopt;
61 }
62
63 std::optional<int64_t> maxValue() const {
64 return data_.has_max_value ? std::optional(data_.max_value) : std::nullopt;
65 }
66
67 std::optional<int64_t> step() const {
68 return data_.has_step ? std::optional(data_.step) : std::nullopt;
69 }
70
71 bool confirm() const { return data_.confirm; }
78 std::optional<int64_t> optionAt(uintptr_t index) const {
79 if (!input_) return std::nullopt;
80 int64_t out = 0;
81 if (ffi::inputIntOptionAt(input_, index, &out)) return out;
82 return std::nullopt;
83 }
84
85 private:
86 ffi::InputInt data_;
87 const ffi::Input* input_ = nullptr;
89};
90
91} // namespace inputs
92} // namespace openpine
Wrapper for a single script input (borrowed from ScriptInfo).
InputInt(const ffi::InputInt &data, const ffi::Input *input=nullptr)
Constructs from FFI data and optional handle for optionAt().
Definition input_int.hpp:30
std::optional< int64_t > step() const
Optional step.
Definition input_int.hpp:67
std::optional< int64_t > maxValue() const
Optional maximum value.
Definition input_int.hpp:63
std::optional< std::string_view > tooltip() const
Optional tooltip.
Definition input_int.hpp:41
bool confirm() const
Whether the input requires confirmation.
Definition input_int.hpp:71
std::optional< int64_t > minValue() const
Optional minimum value.
Definition input_int.hpp:59
int64_t defaultValue() const
Default value.
Definition input_int.hpp:35
bool active() const
Whether the input is active.
Definition input_int.hpp:55
std::optional< std::string_view > inlineGroup() const
Optional inline group name.
Definition input_int.hpp:45
int64_t id() const
Input ID.
Definition input_int.hpp:33
uint64_t display() const
Display bitmask.
Definition input_int.hpp:53
std::optional< std::string_view > group() const
Optional group name.
Definition input_int.hpp:49
std::optional< std::string_view > title() const
Optional title.
Definition input_int.hpp:37
std::optional< int64_t > optionAt(uintptr_t index) const
Option value at the given index.
Definition input_int.hpp:78
uintptr_t optionsLength() const
Number of options (for optionAt()).
Definition input_int.hpp:57
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.
Shared helpers for converting C ABI string refs to std::string_view.
Re-exports FFI types into the openpine namespace.