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
3
#include <
pineforge/run_failure.hpp
>
4
5
#include <cstddef>
6
#include <cstdint>
7
8
namespace
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.
12
class
MapCapacityError
:
public
coded
<std::runtime_error> {
13
public
:
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
21
namespace
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.
26
std::uint64_t
map_pair_limit
() noexcept;
27
std
::uint64_t
exchange_map_pair_limit
(
std
::uint64_t maximum) noexcept;
28
int
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.
35
struct
MapBarContext
{
36
const
int
*
native_bar
=
nullptr
;
37
bool
use_ambient_context
=
true
;
38
};
39
40
MapBarContext
push_map_bar_context
(
const
int
* native_bar)
noexcept
;
41
void
restore_map_bar_context
(
MapBarContext
previous)
noexcept
;
42
43
class
MapBarContextScope
{
44
public
:
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)) {}
48
MapBarContextScope
(
const
MapBarContextScope
&) =
delete
;
49
MapBarContextScope
&
operator=
(
const
MapBarContextScope
&) =
delete
;
50
~MapBarContextScope
() {
restore_map_bar_context
(previous_); }
51
52
private
:
53
MapBarContext
previous_;
54
};
55
56
class
MapPairLimitScope
{
57
public
:
58
explicit
MapPairLimitScope
(std::uint64_t maximum) noexcept
59
: previous_(
exchange_map_pair_limit
(maximum)) {}
60
MapPairLimitScope
(
const
MapPairLimitScope
&) =
delete
;
61
MapPairLimitScope
&
operator=
(
const
MapPairLimitScope
&) =
delete
;
62
~MapPairLimitScope
() {
exchange_map_pair_limit
(previous_); }
63
64
private
:
65
std::uint64_t previous_;
66
};
67
68
}
// namespace detail
69
}
// namespace pineforge
pineforge::MapCapacityError::maxSize
const std::uint64_t maxSize
Definition
map_capacity.hpp:16
pineforge::MapCapacityError::code
static constexpr const char * code
Definition
map_capacity.hpp:15
pineforge::MapCapacityError::MapCapacityError
MapCapacityError(std::uint64_t maximum, std::uint64_t current, std::int64_t bar)
pineforge::MapCapacityError::currSize
const std::uint64_t currSize
Definition
map_capacity.hpp:17
pineforge::MapCapacityError::bar_index
const std::int64_t bar_index
Definition
map_capacity.hpp:18
pineforge::coded< std::runtime_error >::coded
coded(RunFailureCode code, const RunFailureArgs &args, const std::string &what)
Definition
run_failure.hpp:276
pineforge::detail::MapBarContextScope::MapBarContextScope
MapBarContextScope(const MapBarContextScope &)=delete
pineforge::detail::MapBarContextScope::operator=
MapBarContextScope & operator=(const MapBarContextScope &)=delete
pineforge::detail::MapBarContextScope::MapBarContextScope
MapBarContextScope(const int *native_bar=nullptr) noexcept
Definition
map_capacity.hpp:46
pineforge::detail::MapBarContextScope::~MapBarContextScope
~MapBarContextScope()
Definition
map_capacity.hpp:50
pineforge::detail::MapPairLimitScope::MapPairLimitScope
MapPairLimitScope(const MapPairLimitScope &)=delete
pineforge::detail::MapPairLimitScope::~MapPairLimitScope
~MapPairLimitScope()
Definition
map_capacity.hpp:62
pineforge::detail::MapPairLimitScope::MapPairLimitScope
MapPairLimitScope(std::uint64_t maximum) noexcept
Definition
map_capacity.hpp:58
pineforge::detail::MapPairLimitScope::operator=
MapPairLimitScope & operator=(const MapPairLimitScope &)=delete
pineforge::detail
Definition
array.hpp:46
pineforge::detail::restore_map_bar_context
void restore_map_bar_context(MapBarContext previous) noexcept
pineforge::detail::map_capacity_error
void map_capacity_error(std::uint64_t maximum, std::uint64_t current)
pineforge::detail::push_map_bar_context
MapBarContext push_map_bar_context(const int *native_bar) noexcept
pineforge::detail::set_map_pair_limit_checked
int set_map_pair_limit_checked(const std::int64_t *maximum, char *error, std::size_t capacity) noexcept
pineforge::detail::map_pair_limit
std::uint64_t map_pair_limit() noexcept
pineforge::detail::exchange_map_pair_limit
std::uint64_t exchange_map_pair_limit(std::uint64_t maximum) noexcept
pineforge
Definition
array.hpp:42
std
Definition
native_order.hpp:3063
run_failure.hpp
pineforge::detail::MapBarContext
Definition
map_capacity.hpp:35
pineforge::detail::MapBarContext::native_bar
const int * native_bar
Definition
map_capacity.hpp:36
pineforge::detail::MapBarContext::use_ambient_context
bool use_ambient_context
Definition
map_capacity.hpp:37
include
pineforge
map_capacity.hpp
PineForge unreleased — Apache-2.0 —
github.com/pineforge-4pass/pineforge-engine
—
pineforge.dev