ORE Studio 0.0.4
Loading...
Searching...
No Matches
generation_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_UTILITY_GENERATION_GENERATION_CONTEXT_HPP
21#define ORES_UTILITY_GENERATION_GENERATION_CONTEXT_HPP
22
23#include <memory>
24#include "ores.utility/generation/generation_engine.hpp"
25#include "ores.utility/generation/generation_environment.hpp"
26
27namespace ores::utility::generation {
28
37class generation_context final {
38public:
39 using entries = generation_environment::entries;
40
44 explicit generation_context(std::uint64_t seed, entries initial = {});
45
49 explicit generation_context(entries initial = {});
50
54 generation_context child(entries overrides) const;
55
59 generation_engine& engine() { return *engine_; }
60
64 const generation_environment& env() const { return *env_; }
65
66 // Convenience delegations to engine
67 std::uint64_t seed() const { return engine_->seed(); }
68 boost::uuids::uuid generate_uuid() { return engine_->generate_uuid(); }
69 int random_int(int min, int max) { return engine_->random_int(min, max); }
70 bool random_bool(double probability = 0.5) {
71 return engine_->random_bool(probability);
72 }
73 std::chrono::system_clock::time_point past_timepoint(int years_back = 3) {
74 return engine_->past_timepoint(years_back);
75 }
76 std::string alphanumeric(std::size_t length) {
77 return engine_->alphanumeric(length);
78 }
79
80 template<typename T>
81 const T& pick(const std::vector<T>& items) {
82 return engine_->pick(items);
83 }
84
85 template<typename T, std::size_t N>
86 const T& pick(const std::array<T, N>& items) {
87 return engine_->pick(items);
88 }
89
90private:
91 generation_context(std::shared_ptr<generation_engine> engine,
92 std::shared_ptr<const generation_environment> env);
93
94 std::shared_ptr<generation_engine> engine_;
95 std::shared_ptr<const generation_environment> env_;
96};
97
98}
99
100#endif
Utilities for reading environment variables.
Definition environment.hpp:31
Combines a generation engine with a scoped environment.
Definition generation_context.hpp:37
const generation_environment & env() const
Returns the generation environment.
Definition generation_context.hpp:64
generation_context(std::uint64_t seed, entries initial={})
Constructs a context with a specific seed and optional entries.
Definition generation_context.cpp:24
generation_context child(entries overrides) const
Creates a child context with the same engine but overridden env.
Definition generation_context.cpp:38
generation_engine & engine()
Returns the generation engine.
Definition generation_context.hpp:59
Random generation engine with seed-controlled repeatability.
Definition generation_engine.hpp:41
Scoped key-value store for generation context data.
Definition generation_environment.hpp:37