inkcpp
Loading...
Searching...
No Matches
choice.h
1/* Copyright (c) 2024 Julian Benda
2 *
3 * This file is part of inkCPP which is released under MIT license.
4 * See file LICENSE.txt or go to
5 * https://github.com/JBenda/inkcpp for full license details.
6 */
7#pragma once
8#include "system.h"
9
10namespace ink
11{
12namespace runtime
13{
14 namespace internal
15 {
16 class basic_stream;
17 class runner_impl;
18 class string_table;
19 class list_table;
20 } // namespace internal
21
31 class choice
32 {
33 public:
42 int index() const { return _index; }
43
51 const char* text() const { return _text; }
52
54 choice()
55 : choice(0)
56 {
57 }
58
60 choice(int)
61 : _tags{nullptr}
62 , _text{nullptr}
63 , _index{~0}
64 , _path{~0u}
65 , _thread{~0u}
66 {
67 }
68
70 bool has_tags() const { return _tags != nullptr; }
71
75 size_t num_tags() const
76 {
77 size_t i = 0;
78 if (has_tags())
79 while (_tags[i] != nullptr) {
80 ++i;
81 };
82 return i;
83 }
84
86 const char* get_tag(size_t index) const { return _tags[index]; }
87
88 private:
89 friend class internal::runner_impl;
90
91 uint32_t path() const { return _path; }
92
93 choice& setup(
94 internal::basic_stream&, internal::string_table& strings, internal::list_table& lists,
95 int index, uint32_t path, thread_t thread, const char* const* tags
96 );
97
98 protected:
99 const char* const* _tags;
100 const char* _text;
101 int _index;
102 uint32_t _path;
103 thread_t _thread;
104 };
105} // namespace runtime
106} // namespace ink
An ink choice that is being presented to the user.
Definition choice.h:32
bool has_tags() const
does this choice has tags?
Definition choice.h:70
size_t num_tags() const
number of tags assoziated with this choice
Definition choice.h:75
const char * text() const
Choice text.
Definition choice.h:51
int index() const
Choice index.
Definition choice.h:42
const char * get_tag(size_t index) const
access tag.
Definition choice.h:86
Namespace contaning all modules and classes from InkCPP.
Definition choice.h:11
unsigned int uint32_t
define basic numeric type
Definition system.h:47
uint32_t thread_t
Used to uniquely identify threads.
Definition system.h:81