inkcpp
Loading...
Searching...
No Matches
list.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
9#include "system.h"
10
11#ifdef INK_ENABLE_STL
12# include <ostream>
13#endif
14
15#ifdef INKCPP_BUILD_CLIB
16struct InkListIter;
17struct HInkList;
19int ink_list_flags_from(const HInkList*, const char*, InkListIter*);
20int ink_list_iter_next(InkListIter*);
21#endif
22
23namespace ink::runtime
24{
25namespace internal
26{
27 class list_table;
28} // namespace internal
29
43{
44public:
46 : _list_table{nullptr}
47 , _list{-1}
48 {
49 }
50
51 virtual list_interface& operator=(const list_interface&) = default;
52
53 virtual ~list_interface() {}
54
59 {
60 const char* _flag_name;
61 const char* _list_name;
62 const list_interface& _list;
63 int _i;
64 bool _one_list_iterator;
65 friend list_interface;
66#ifdef INKCPP_BUILD_CLIB
67 friend int ::ink_list_flags(const HInkList*, InkListIter*);
68 friend int ::ink_list_flags_from(const HInkList*, const char*, InkListIter*);
69 friend int ::ink_list_iter_next(InkListIter* self);
70#endif
71
72 protected:
74 iterator(const char* flag_name, const list_interface& list, int i, bool one_list_only = false)
75 : _flag_name(flag_name)
76 , _list_name(nullptr)
77 , _list(list)
78 , _i(i)
79 , _one_list_iterator(one_list_only)
80 {
81 }
82
83 public:
85 struct Flag {
86 const char* flag_name;
87 const char* list_name;
88#ifdef INK_ENABLE_STL
93 friend std::ostream& operator<<(std::ostream& os, const Flag& flag)
94 {
95 os << flag.list_name << "(" << flag.flag_name << ")";
96 return os;
97 }
98#endif
99 };
100
102 Flag operator*() const { return Flag{_flag_name, _list_name}; };
103
106 {
107 _list.next(_flag_name, _list_name, _i, _one_list_iterator);
108 return *this;
109 }
110
114 bool operator!=(const iterator& itr) const { return itr._i != _i; }
115
119 bool operator==(const iterator& itr) const { return itr._i == _i; }
120
121 iterator& operator=(const iterator&) = delete;
122 };
123
124
125#ifdef __GNUC__
126# pragma GCC diagnostic push
127# pragma GCC diagnostic ignored "-Wunused-parameter"
128#else
129# pragma warning(push)
130# pragma warning( \
131 disable : 4100, justification : "non functional prototypes do not need the argument." \
132 )
133#endif
134
136 virtual bool contains(const char* flag) const
137 {
138 inkAssert(false, "Not implemented function from interfaces is called!");
139 return false;
140 };
141
143 virtual void add(const char* flag)
144 {
145 inkAssert(false, "Not implemented function from interface is called!");
146 };
147
149 virtual void remove(const char* flag)
150 {
151 inkAssert(false, "Not implemented function from interface is called!");
152 };
153
155 virtual iterator begin() const
156 {
157 inkAssert(false, "Not implemented function from interface is called!");
158 return new_iterator(nullptr, -1);
159 };
160
162 virtual iterator begin(const char* list_name) const
163 {
164 inkAssert(false, "Not implemented function from interface is called!");
165 return new_iterator(nullptr, -1);
166 }
167
169 virtual iterator end() const
170 {
171 inkAssert(false, "Not implemented function from interface is called!");
172 return new_iterator(nullptr, -1);
173 };
174
175private:
176 friend iterator;
177
178 virtual void
179 next(const char*& flag_name, const char*& list_name, int& i, bool _one_list_iterator) const
180 {
181 inkAssert(false, "Not implemented funciton from interface is called!");
182 };
183
184#ifdef __GNUC__
185# pragma GCC diagnostic pop
186#else
187# pragma warning(pop)
188#endif
189
190protected:
192 iterator new_iterator(const char* flag_name, int i, bool one_list_only = false) const
193 {
194 return iterator(flag_name, *this, i, one_list_only);
195 }
196
198 list_interface(internal::list_table& table, int list)
199 : _list_table{&table}
200 , _list{list}
201 {
202 }
203
205 internal::list_table* _list_table;
206 int _list;
207};
208
209} // namespace ink::runtime
Handler for a ink list.
int ink_list_flags_from(const HInkList *self, const char *list_name, InkListIter *iter)
Creates an Iterator over all flags contained in a list assziated with a defined list.
int ink_list_flags(const HInkList *self, InkListIter *iter)
Creates an Iterator over all flags contained in a list.
iterater for flags in a list
Definition list.h:59
iterator & operator++()
continue iterator to next value
Definition list.h:105
bool operator!=(const iterator &itr) const
checks if iterator points not to the same element
Definition list.h:114
Flag operator*() const
access value the iterator is pointing to
Definition list.h:102
bool operator==(const iterator &itr) const
checks if iterator points to the same element
Definition list.h:119
Interface for accessing a Ink list.
Definition list.h:43
virtual bool contains(const char *flag) const
checks if a flag is contained in the list
Definition list.h:136
virtual iterator begin() const
begin iterator for contained flags in list
Definition list.h:155
virtual void remove(const char *flag)
removes a flag from list
Definition list.h:149
virtual void add(const char *flag)
add a flag to list
Definition list.h:143
virtual iterator begin(const char *list_name) const
returns a iterator over elements of the given list
Definition list.h:162
virtual iterator end() const
end iterator for contained flags in list
Definition list.h:169
Contaning all modules and classes used for the inkles ink runtime.
Definition choice.h:13
list_interface * list
alias for ink::runtime::list_interface pointer
Definition types.h:24
Iterater used to iterate flags of a HInkList.
Definition inkcpp.h:152
contains flag data
Definition list.h:85
const char * flag_name
name of the flag
Definition list.h:86
const char * list_name
name of the list
Definition list.h:87
friend std::ostream & operator<<(std::ostream &os, const Flag &flag)
serelization operator
Definition list.h:93