PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
map_capacity.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstddef>
6#include <cstdint>
7
8namespace pineforge {
9
10// A configured map's first refused DISTINCT insertion. Counts are owned by
11// the map; replacing a key never reaches this exception.
12class MapCapacityError : public coded<std::runtime_error> {
13public:
14 MapCapacityError(std::uint64_t maximum, std::uint64_t current, std::int64_t bar);
15 static constexpr const char* code = "RE10070";
16 const std::uint64_t maxSize;
17 const std::uint64_t currSize;
18 const std::int64_t bar_index;
19};
20
21namespace detail {
22
23// The thread's creation policy. A host captures it before its constructor
24// creates maps and reinstalls it around script preparation and callbacks.
25// Every map stores its own copy. Zero means no pair limit.
26std::uint64_t map_pair_limit() noexcept;
27std::uint64_t exchange_map_pair_limit(std::uint64_t maximum) noexcept;
28int set_map_pair_limit_checked(const std::int64_t* maximum,
29 char* error, std::size_t capacity) noexcept;
30[[noreturn]] void map_capacity_error(std::uint64_t maximum, std::uint64_t current);
31
32// Borrowed call context, never durable state. Native callbacks use their own
33// engine's live bar index; a Pine evaluation selects its installed TA context.
34// Scope restoration prevents a nested engine from borrowing its parent's bar.
36 const int* native_bar = nullptr;
38};
39
40MapBarContext push_map_bar_context(const int* native_bar) noexcept;
41void restore_map_bar_context(MapBarContext previous) noexcept;
42
44public:
45 // nullptr selects Pine context while retaining the native fallback.
46 explicit MapBarContextScope(const int* native_bar = nullptr) noexcept
47 : previous_(push_map_bar_context(native_bar)) {}
51
52private:
53 MapBarContext previous_;
54};
55
57public:
58 explicit MapPairLimitScope(std::uint64_t maximum) noexcept
59 : previous_(exchange_map_pair_limit(maximum)) {}
63
64private:
65 std::uint64_t previous_;
66};
67
68} // namespace detail
69} // namespace pineforge
const std::uint64_t maxSize
static constexpr const char * code
MapCapacityError(std::uint64_t maximum, std::uint64_t current, std::int64_t bar)
const std::uint64_t currSize
const std::int64_t bar_index
coded(RunFailureCode code, const RunFailureArgs &args, const std::string &what)
MapBarContextScope(const MapBarContextScope &)=delete
MapBarContextScope & operator=(const MapBarContextScope &)=delete
MapBarContextScope(const int *native_bar=nullptr) noexcept
MapPairLimitScope(const MapPairLimitScope &)=delete
MapPairLimitScope(std::uint64_t maximum) noexcept
MapPairLimitScope & operator=(const MapPairLimitScope &)=delete
void restore_map_bar_context(MapBarContext previous) noexcept
void map_capacity_error(std::uint64_t maximum, std::uint64_t current)
MapBarContext push_map_bar_context(const int *native_bar) noexcept
int set_map_pair_limit_checked(const std::int64_t *maximum, char *error, std::size_t capacity) noexcept
std::uint64_t map_pair_limit() noexcept
std::uint64_t exchange_map_pair_limit(std::uint64_t maximum) noexcept