OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
display.hpp
Go to the documentation of this file.
1#pragma once
2
11
12#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 201703L
13#error "OpenPine C++ wrapper headers require C++17."
14#endif
15
16#include <cstdint>
17
18#include "ffi.hpp"
19
20namespace openpine {
21
25class Display {
26 private:
27 uint32_t bits_;
28
29 public:
33 constexpr Display() : bits_(0) {}
34
40 constexpr explicit Display(uint32_t bits) : bits_(bits) {}
41
45 static constexpr Display all() { return Display(ffi::DISPLAY_ALL); }
46
50 static constexpr Display none() { return Display(ffi::DISPLAY_NONE); }
51
55
59 static const Display ALL;
60
64 static const Display NONE;
65
69 static const Display DATA_WINDOW;
70
74 static const Display PANE;
75
79 static const Display PINE_SCREENER;
80
84 static const Display PRICE_SCALE;
85
89 static const Display STATUS_LINE;
90
94 constexpr uint32_t bits() const { return bits_; }
95
99 constexpr bool empty() const { return bits_ == 0; }
100
104 constexpr bool contains(Display other) const {
105 return (bits_ & other.bits_) == other.bits_;
106 }
107
111 constexpr Display& operator|=(Display other) {
112 bits_ |= other.bits_;
113 return *this;
114 }
115
119 constexpr Display& operator&=(Display other) {
120 bits_ &= other.bits_;
121 return *this;
122 }
123
127 explicit constexpr operator uint32_t() const { return bits_; }
128
132 friend constexpr bool operator==(Display a, Display b) {
133 return a.bits_ == b.bits_;
134 }
135
139 friend constexpr bool operator!=(Display a, Display b) {
140 return a.bits_ != b.bits_;
141 }
142
146 friend constexpr Display operator|(Display a, Display b) {
147 return Display(a.bits_ | b.bits_);
148 }
149
153 friend constexpr Display operator&(Display a, Display b) {
154 return Display(a.bits_ & b.bits_);
155 }
156
160 friend constexpr Display operator~(Display a) { return Display(~a.bits_); }
161};
162
163// Inline definitions for `Display` common masks.
164inline constexpr Display Display::ALL{ffi::DISPLAY_ALL};
165inline constexpr Display Display::NONE{ffi::DISPLAY_NONE};
166inline constexpr Display Display::DATA_WINDOW{ffi::DISPLAY_DATA_WINDOW};
167inline constexpr Display Display::PANE{ffi::DISPLAY_PANE};
168inline constexpr Display Display::PINE_SCREENER{ffi::DISPLAY_PINE_SCREENER};
169inline constexpr Display Display::PRICE_SCALE{ffi::DISPLAY_PRICE_SCALE};
170inline constexpr Display Display::STATUS_LINE{ffi::DISPLAY_STATUS_LINE};
171
172} // namespace openpine
A type-safe display bitmask.
Definition display.hpp:25
static const Display ALL
Common display masks mirroring the C ABI constants.
Definition display.hpp:59
friend constexpr Display operator~(Display a)
Bitwise NOT.
Definition display.hpp:160
static const Display NONE
Show nowhere.
Definition display.hpp:64
static const Display PINE_SCREENER
Show in Pine screener.
Definition display.hpp:79
friend constexpr Display operator&(Display a, Display b)
Bitwise AND.
Definition display.hpp:153
static constexpr Display all()
Returns a mask that enables all known display surfaces.
Definition display.hpp:45
constexpr Display()
Constructs an empty display mask.
Definition display.hpp:33
static const Display STATUS_LINE
Show in status line.
Definition display.hpp:89
constexpr Display & operator&=(Display other)
Bitwise AND-assign.
Definition display.hpp:119
static const Display PANE
Show in pane.
Definition display.hpp:74
static const Display DATA_WINDOW
Show in data window.
Definition display.hpp:69
static constexpr Display none()
Returns a mask that disables all display surfaces.
Definition display.hpp:50
friend constexpr bool operator!=(Display a, Display b)
Inequality compare.
Definition display.hpp:139
static const Display PRICE_SCALE
Show on price scale.
Definition display.hpp:84
constexpr uint32_t bits() const
Returns the raw bitmask value.
Definition display.hpp:94
constexpr bool empty() const
Returns whether the mask has no bits set.
Definition display.hpp:99
friend constexpr Display operator|(Display a, Display b)
Bitwise OR.
Definition display.hpp:146
constexpr Display & operator|=(Display other)
Bitwise OR-assign.
Definition display.hpp:111
friend constexpr bool operator==(Display a, Display b)
Equality compare.
Definition display.hpp:132
constexpr Display(uint32_t bits)
Constructs a display mask from raw bits.
Definition display.hpp:40
constexpr bool contains(Display other) const
Returns whether this mask fully contains all bits in other.
Definition display.hpp:104