OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
input_time_frame.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 InputTimeFrame(const ffi::InputTimeFrame& data,
31 const ffi::Input* input = nullptr)
32 : data_(data), input_(input) {}
33
34 int64_t id() const { return data_.id; }
36 bool isChartDefault() const { return data_.is_chart_default; }
41 std::optional<TimeFrame> defaultValue() const {
42 if (data_.is_chart_default) return std::nullopt;
43 return data_.default_value;
44 }
45
46 std::optional<std::string_view> title() const {
47 return detail::optRefToView(data_.has_title, data_.title);
48 }
49
50 std::optional<std::string_view> tooltip() const {
51 return detail::optRefToView(data_.has_tooltip, data_.tooltip);
52 }
53
54 std::optional<std::string_view> inlineGroup() const {
55 return detail::optRefToView(data_.has_inline, data_.inline_);
56 }
57
58 std::optional<std::string_view> group() const {
59 return detail::optRefToView(data_.has_group, data_.group);
60 }
61
62 uint64_t display() const { return data_.display; }
64 bool active() const { return data_.active; }
66 uintptr_t optionsLength() const { return data_.options_length; }
68 bool confirm() const { return data_.confirm; }
75 std::optional<std::string_view> optionAt(uintptr_t index) const {
76 if (!input_) return std::nullopt;
77 ffi::PineStringRef ref{};
78 if (!ffi::inputTimeFrameOptionAt(input_, index, &ref)) return std::nullopt;
79 return detail::optRefToView(ref.data != nullptr, ref);
80 }
81
82 private:
83 ffi::InputTimeFrame data_;
84 const ffi::Input* input_ = nullptr;
86};
87
88} // namespace inputs
89} // namespace openpine
Wrapper for a single script input (borrowed from ScriptInfo).
InputTimeFrame(const ffi::InputTimeFrame &data, const ffi::Input *input=nullptr)
Constructs from FFI data and optional handle for optionAt().
uintptr_t optionsLength() const
Number of options (for optionAt()).
std::optional< std::string_view > inlineGroup() const
Optional inline group name.
std::optional< TimeFrame > defaultValue() const
Default timeframe (quantity + unit).
std::optional< std::string_view > tooltip() const
Optional tooltip.
bool isChartDefault() const
Whether the default is "use chart timeframe".
std::optional< std::string_view > title() const
Optional title.
std::optional< std::string_view > group() const
Optional group name.
std::optional< std::string_view > optionAt(uintptr_t index) const
Option timeframe string at the given index.
bool confirm() const
Whether the input requires confirmation.
bool active() const
Whether the input is active.
uint64_t display() const
Display bitmask.
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.