ORE Studio 0.0.4
Loading...
Searching...
No Matches
pagination_context.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_SHELL_APP_PAGINATION_CONTEXT_HPP
21#define ORES_SHELL_APP_PAGINATION_CONTEXT_HPP
22
23#include <string>
24#include <cstdint>
25#include <functional>
26#include <unordered_map>
27
28namespace ores::shell::app {
29
35 std::uint32_t current_offset = 0;
37 std::uint32_t total_count = 0;
38};
39
43using list_callback = std::function<void(std::ostream&)>;
44
52public:
53 pagination_context() = default;
54
59 std::uint32_t page_size() const;
60
65 void set_page_size(std::uint32_t size);
66
72 entity_page_state& state_for(const std::string& entity_name);
73
78 const std::string& last_entity() const;
79
84 void set_last_entity(const std::string& name);
85
91 void register_list_callback(const std::string& entity_name,
92 list_callback callback);
93
99 const list_callback* get_list_callback(const std::string& entity_name) const;
100
101private:
102 std::uint32_t page_size_ = 20;
103 std::string last_entity_;
104 std::unordered_map<std::string, entity_page_state> entity_states_;
105 std::unordered_map<std::string, list_callback> list_callbacks_;
106};
107
108}
109
110#endif
Application hosting for the interactive shell.
Definition application.hpp:28
std::function< void(std::ostream &)> list_callback
Callback type for re-invoking list commands during navigation.
Definition pagination_context.hpp:43
State for a single entity's pagination.
Definition pagination_context.hpp:33
std::uint32_t total_count
Total count of available records (from last response)
Definition pagination_context.hpp:37
std::uint32_t current_offset
Current offset in the result set.
Definition pagination_context.hpp:35
Manages pagination state across shell commands.
Definition pagination_context.hpp:51
void register_list_callback(const std::string &entity_name, list_callback callback)
Register a callback for listing an entity.
Definition pagination_context.cpp:48
void set_page_size(std::uint32_t size)
Set the page size.
Definition pagination_context.cpp:28
entity_page_state & state_for(const std::string &entity_name)
Get or create pagination state for an entity.
Definition pagination_context.cpp:36
const std::string & last_entity() const
Get the last entity that was listed.
Definition pagination_context.cpp:40
const list_callback * get_list_callback(const std::string &entity_name) const
Get the list callback for an entity.
Definition pagination_context.cpp:54
std::uint32_t page_size() const
Get the current page size.
Definition pagination_context.cpp:24
void set_last_entity(const std::string &name)
Set the last entity that was listed.
Definition pagination_context.cpp:44