OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
input_string.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 InputString(const ffi::InputString& data, const ffi::Input* input = nullptr)
31 : data_(data), input_(input) {}
32
33 int64_t id() const { return data_.id; }
35 std::string_view defaultValue() const {
36 return detail::refToView(data_.default_value);
37 }
38
39 std::optional<std::string_view> title() const {
40 return detail::optRefToView(data_.has_title, data_.title);
41 }
42
43 std::optional<std::string_view> tooltip() const {
44 return detail::optRefToView(data_.has_tooltip, data_.tooltip);
45 }
46
47 std::optional<std::string_view> inlineGroup() const {
48 return detail::optRefToView(data_.has_inline, data_.inline_);
49 }
50
51 std::optional<std::string_view> group() const {
52 return detail::optRefToView(data_.has_group, data_.group);
53 }
54
55 uint64_t display() const { return data_.display; }
57 bool active() const { return data_.active; }
59 uintptr_t optionsLength() const { return data_.options_length; }
61 bool confirm() const { return data_.confirm; }
68 std::optional<std::string_view> optionAt(uintptr_t index) const {
69 if (!input_) return std::nullopt;
70 ffi::PineStringRef ref{};
71 if (!ffi::inputStringOptionAt(input_, index, &ref)) return std::nullopt;
72 return detail::optRefToView(ref.data != nullptr, ref);
73 }
74
75 private:
76 ffi::InputString data_;
77 const ffi::Input* input_ = nullptr;
79};
80
81} // namespace inputs
82} // namespace openpine
Wrapper for a single script input (borrowed from ScriptInfo).
bool active() const
Whether the input is active.
std::optional< std::string_view > group() const
Optional group name.
std::optional< std::string_view > tooltip() const
Optional tooltip.
std::string_view defaultValue() const
Default value.
InputString(const ffi::InputString &data, const ffi::Input *input=nullptr)
Constructs from FFI data and optional handle for optionAt().
uint64_t display() const
Display bitmask.
bool confirm() const
Whether the input requires confirmation.
int64_t id() const
Input ID.
std::optional< std::string_view > title() const
Optional title.
std::optional< std::string_view > optionAt(uintptr_t index) const
Option string at the given index.
std::optional< std::string_view > inlineGroup() const
Optional inline group name.
uintptr_t optionsLength() const
Number of options (for optionAt()).
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.
Re-exports FFI types into the openpine namespace.