OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
input_float.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
28 public:
30 InputFloat(const ffi::InputFloat& data, const ffi::Input* input = nullptr)
31 : data_(data), input_(input) {}
32
33 int64_t id() const { return data_.id; }
35 double 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 bool hasOptions() const { return data_.has_options; }
59 uintptr_t optionsLength() const { return data_.options_length; }
61 std::optional<double> minValue() const {
62 return data_.has_min_value ? std::optional(data_.min_value) : std::nullopt;
63 }
64
65 std::optional<double> maxValue() const {
66 return data_.has_max_value ? std::optional(data_.max_value) : std::nullopt;
67 }
68
69 std::optional<double> step() const {
70 return data_.has_step ? std::optional(data_.step) : std::nullopt;
71 }
72
73 bool confirm() const { return data_.confirm; }
80 std::optional<double> optionAt(uintptr_t index) const {
81 if (!input_) return std::nullopt;
82 double out = 0;
83 if (ffi::inputFloatOptionAt(input_, index, &out)) return out;
84 return std::nullopt;
85 }
86
87 private:
88 ffi::InputFloat data_;
89 const ffi::Input* input_ = nullptr;
91};
92
93} // namespace inputs
94} // namespace openpine
Wrapper for a single script input (borrowed from ScriptInfo).
uintptr_t optionsLength() const
Number of options (for optionAt()).
std::optional< double > optionAt(uintptr_t index) const
Option value at the given index.
uint64_t display() const
Display bitmask.
bool active() const
Whether the input is active.
InputFloat(const ffi::InputFloat &data, const ffi::Input *input=nullptr)
Constructs from FFI data and optional handle for optionAt().
bool confirm() const
Whether the input requires confirmation.
std::optional< double > step() const
Optional step.
bool hasOptions() const
Whether options are present.
std::optional< std::string_view > title() const
Optional title.
std::optional< std::string_view > tooltip() const
Optional tooltip.
double defaultValue() const
Default value.
std::optional< double > maxValue() const
Optional maximum value.
std::optional< double > minValue() const
Optional minimum value.
int64_t id() const
Input ID.
std::optional< std::string_view > inlineGroup() const
Optional inline group name.
std::optional< std::string_view > group() const
Optional group name.
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.