3#include <clingo/core.hh>
5#include <clingo/stats.h>
44 return static_cast<StatsType>(Detail::call<clingo_stats_type>(stats_, key_));
79 return Detail::call<clingo_stats_value_get>(stats_, key_);
81 throw std::logic_error{
"not a value"};
95 return std::string{
bld.str()};
141 throw std::logic_error{
"not a value"};
171 using pointer = Detail::ArrowProxy<value_type>;
173 using iterator = Detail::RandomAccessIterator<ConstStatsArray>;
190 [[
nodiscard]]
auto size()
const ->
size_t {
return Detail::call<clingo_stats_array_size>(stats_, key_); }
205 return Detail::call<clingo_stats_array_at>(stats_, key_, index);
216 throw std::logic_error{
"not an array"};
235 using pointer = Detail::ArrowProxy<value_type>;
237 using iterator = Detail::RandomAccessIterator<StatsArray>;
256 return Stats{stats_(),
257 Detail::call<clingo_stats_array_push>(stats_(), key_,
static_cast<clingo_stats_type_t>(type))};
270 for (; n < index; ++n) {
271 std::ignore =
push(type);
293 throw std::logic_error{
"not an array"};
315 using pointer = Detail::ArrowProxy<value_type>;
317 using iterator = Detail::RandomAccessIterator<ConstStatsMap>;
328 [[
nodiscard]]
auto size()
const ->
size_t {
return Detail::call<clingo_stats_map_size>(stats_, key_); }
335 auto [name,
subkey] = at_(index);
350 return Detail::call<clingo_stats_map_has_subkey>(stats_, key_, name.data(), name.size());
367 return Detail::call<clingo_stats_map_at>(stats_, key_, name.data(), name.size());
370 [[
nodiscard]]
auto at_(
size_t index)
const -> std::pair<std::string_view, uint64_t> {
371 auto [data,
size] = Detail::call<clingo_stats_map_subkey_name>(stats_, key_, index);
372 auto str = std::string_view{data,
size};
373 return {str, at_(str)};
384 throw std::logic_error{
"not a map"};
407 using pointer = Detail::ArrowProxy<value_type>;
409 using iterator = Detail::RandomAccessIterator<StatsMap>;
419 auto [name,
subkey] = at_(index);
441 return Stats{stats_(), Detail::call<clingo_stats_map_add_subkey>(stats_(), key_, name.data(), name.size(),
466 throw std::logic_error{
"not a map"};
Class modeling an immutable view on an array of statistics entries.
Definition stats.hh:160
auto begin() const -> iterator
Get an iterator to the beginning of the array.
Definition stats.hh:195
auto end() const -> iterator
Get an iterator to the end of the array.
Definition stats.hh:200
auto size() const -> size_t
Get the size of the array.
Definition stats.hh:190
ConstStats value_type
The value type of the array, which are stats entries.
Definition stats.hh:163
std::ptrdiff_t difference_type
The difference type of the array.
Definition stats.hh:167
ConstStatsArray(clingo_stats_t const *stats, uint64_t key)
Construct a statistics array from a pointer to the C API and a key.
Definition stats.hh:179
auto operator[](size_t index) const -> ConstStats
Get a statistics entry at the given index if the entry is an array.
Definition stats.hh:185
Detail::ArrowProxy< value_type > pointer
The pointer type of the array, which is a proxy to stats entries.
Definition stats.hh:171
std::size_t size_type
The size type of the array.
Definition stats.hh:165
Detail::RandomAccessIterator< ConstStatsArray > iterator
The iterator type, which is a random access iterator over stats entries.
Definition stats.hh:173
auto at(size_t index) const -> ConstStats
Get a statistics entry at the given index if the entry is an array.
Definition stats.hh:182
Class modeling an immutable view on a map of statistics entries.
Definition stats.hh:300
auto operator[](std::string_view name) const -> ConstStats
Get a statistics entry with the given name if the entry is a map.
Definition stats.hh:340
auto begin() const -> iterator
Get an iterator to the beginning of the map.
Definition stats.hh:356
auto get(std::string_view name) const -> ConstStats
Get a statistics entry with the given name if the entry is a map.
Definition stats.hh:343
std::string_view key_type
The key type of the map, which is a string view.
Definition stats.hh:303
std::ptrdiff_t difference_type
The difference type of the map.
Definition stats.hh:311
auto at(size_t index) const -> value_type
Get the name entry pair at the given index.
Definition stats.hh:334
auto size() const -> size_t
Get the size of the map.
Definition stats.hh:328
auto contains(std::string_view name) const -> bool
Check if the map contains a subkey with the given name.
Definition stats.hh:349
auto end() const -> iterator
Get an iterator to the end of the map.
Definition stats.hh:361
Detail::RandomAccessIterator< ConstStatsMap > iterator
The iterator type, which is a random access iterator over value types.
Definition stats.hh:317
ConstStatsMap(clingo_stats_t const *stats, uint64_t key)
Construct a statistics map from a pointer to the C API and a key.
Definition stats.hh:323
std::size_t size_type
The size type of the map.
Definition stats.hh:309
std::pair< key_type, mapped_type > value_type
The value type of the map, which is a pair of key and mapped type.
Definition stats.hh:307
Detail::ArrowProxy< value_type > pointer
The pointer type of the map, which is a proxy to the value type.
Definition stats.hh:315
value_type reference
The reference type of the map, which is a pair of key and mapped type.
Definition stats.hh:313
Class modeling an immutable view on a statistics entry.
Definition stats.hh:29
auto to_string() const -> std::string
Get a string representation of the statistics entry.
Definition stats.hh:92
auto value() const -> double
Get the value of the statistics entry if it is a value.
Definition stats.hh:77
friend auto c_cast(ConstStats const &stats) -> clingo_stats_t const *
Cast to the underlying C API type.
Definition stats.hh:38
ConstStats(clingo_stats_t const *stats, uint64_t key)
Construct a statistics entry from a pointer to the C API and a key.
Definition stats.hh:32
auto type() const -> StatsType
Get the type of the statistics entry.
Definition stats.hh:43
auto operator*() const -> double
Get the value of the statistics entry if it is a value.
Definition stats.hh:85
Class modeling a mutable view on an array of statistics entries.
Definition stats.hh:224
std::ptrdiff_t difference_type
The difference type of the array.
Definition stats.hh:231
auto ensure(size_t index, StatsType type) const -> Stats
Ensure that the array has an entry at the given index.
Definition stats.hh:265
Detail::RandomAccessIterator< StatsArray > iterator
The iterator type, which is a random access iterator over stats entries.
Definition stats.hh:237
auto at(size_t index) const -> Stats
Get a statistics entry at the given index if the entry is an array.
Definition stats.hh:243
StatsArray(clingo_stats_t *stats, uint64_t key)
Construct a statistics array from a pointer to the C API and a key.
Definition stats.hh:240
Stats value_type
The value type of the array, which are stats entries.
Definition stats.hh:227
Detail::ArrowProxy< value_type > pointer
The pointer type of the array, which is a proxy to stats entries.
Definition stats.hh:235
auto begin() const -> iterator
Get an iterator to the beginning of the array.
Definition stats.hh:277
auto operator[](size_t index) const -> Stats
Get a statistics entry at the given index if the entry is an array.
Definition stats.hh:246
auto push(StatsType type) const -> Stats
Append a new statistics entry of the given type to the array.
Definition stats.hh:255
auto end() const -> iterator
Get an iterator to the end of the array.
Definition stats.hh:280
std::size_t size_type
The size type of the array.
Definition stats.hh:229
Class modeling a mutable view on a map of statistics entries.
Definition stats.hh:392
auto at(size_t index) const -> value_type
Get the name entry pair at the given index.
Definition stats.hh:418
value_type reference
The reference type of the map, which corresponds to the value type.
Definition stats.hh:405
StatsMap(clingo_stats_t *stats, uint64_t key)
Construct a statistics map from a pointer to the C API and a key.
Definition stats.hh:415
std::ptrdiff_t difference_type
The difference type of the map.
Definition stats.hh:403
Detail::RandomAccessIterator< StatsMap > iterator
The iterator type, which is a random access iterator over value types.
Definition stats.hh:409
std::size_t size_type
The size type of the map.
Definition stats.hh:401
auto begin() const -> iterator
Get an iterator to the beginning of the map.
Definition stats.hh:448
std::string_view key_type
The key type of the map, which is a string view.
Definition stats.hh:395
auto insert(std::string_view name, StatsType type) const -> Stats
Insert a statistics entry with the given name and type into the map.
Definition stats.hh:440
auto operator[](std::string_view name) const -> Stats
Get a statistics entry with the given name if the entry is a map.
Definition stats.hh:424
auto end() const -> iterator
Get an iterator to the end of the map.
Definition stats.hh:453
std::pair< key_type, mapped_type > value_type
The value type of the map, which is a pair of key and mapped type.
Definition stats.hh:399
auto get(std::string_view name) const -> Stats
Get a statistics entry with the given name if the entry is a map.
Definition stats.hh:427
Detail::ArrowProxy< value_type > pointer
The pointer type of the map, which is a proxy to the value type.
Definition stats.hh:407
Class modeling a mutable view on a statistics entry.
Definition stats.hh:106
Stats(clingo_stats_t *stats, uint64_t key)
Construct a statistics entry from a pointer to the C API and a key.
Definition stats.hh:109
auto operator=(double value) const -> Stats
Set the value of the statistics entry if it is a value.
Definition stats.hh:147
friend auto c_cast(Stats const &stats) -> clingo_stats_t *
Cast to the underlying C API type.
Definition stats.hh:112
auto value() const -> double
Get the value of the statistics entry if it is a value.
Definition stats.hh:77
void value(double value) const
Set the value of the statistics entry if it is a value.
Definition stats.hh:137
A string builder for constructing strings.
Definition core.hh:524
CLINGO_VISIBILITY_DEFAULT bool clingo_stats_value_set(clingo_stats_t *stats, uint64_t key, double value)
Set the value of the given entry.
CLINGO_VISIBILITY_DEFAULT bool clingo_stats_to_string(clingo_stats_t const *stats, uint64_t key, clingo_string_builder_t *builder)
Get a string representation of the statistics.
int clingo_stats_type_t
Corresponding type to clingo_stats_type.
Definition stats.h:56
struct clingo_statistic clingo_stats_t
Handle for the solver stats.
Definition stats.h:59
@ clingo_stats_type_map
the entry is a map
Definition stats.h:53
@ clingo_stats_type_value
the entry is a (double) value
Definition stats.h:51
@ clingo_stats_type_array
the entry is an array
Definition stats.h:52
@ tuple
Theory tuples "(t1,...,tn)".
@ map
The configuration entry is a map of configurations.
@ value
The configuration entry is a double value.
@ array
The configuration entry is a array of configurations.
auto get(std::string_view name) const -> Stats
Get a statistics entry with the given name if the entry is a map.
Definition stats.hh:469
auto at(size_t index) const -> Stats
Get a statistics entry at the given index if the entry is an array.
Definition stats.hh:295
auto get(std::string_view name) const -> ConstStats
Get a statistics entry with the given name if the entry is a map.
Definition stats.hh:387
auto map() const -> StatsMap
Get a view on the map of statistics entries if the entry is a map.
Definition stats.hh:462
auto map() const -> ConstStatsMap
Get a view on the map of statistics entries if the entry is a map.
Definition stats.hh:380
auto array() const -> StatsArray
Get a view on the array of statistics entries if the entry is an array.
Definition stats.hh:289
auto array() const -> ConstStatsArray
Get a view on the array of statistics entries if the entry is an array.
Definition stats.hh:212
StatsType
Enumeration of statistics types.
Definition stats.hh:14
auto at(size_t index) const -> ConstStats
Get a statistics entry at the given index if the entry is an array.
Definition stats.hh:219
@ map
The statistics entry holds map.
@ value
The statistics entry holds a value.
@ array
The statistics entry holds an array.