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
42class list_interface
43{
44public:
45 list_interface()
46 : _list_table{nullptr}
47 , _list{-1}
48 {
49 }
50
52 virtual list_interface& operator=(const list_interface&) = default;
53
54 virtual ~list_interface() {}
55
59 class iterator
60 {
61 const char* _flag_name;
62 const char* _list_name;
63 const list_interface& _list;
64 int _i;
65 bool _one_list_iterator;
66 friend list_interface;
67#ifdef INKCPP_BUILD_CLIB
68 friend int ::ink_list_flags(const HInkList*, InkListIter*);
69 friend int ::ink_list_flags_from(const HInkList*, const char*, InkListIter*);
70 friend int ::ink_list_iter_next(InkListIter* self);
71#endif
72
73 protected:
75 iterator(const char* flag_name, const list_interface& list, int i, bool one_list_only = false)
76 : _flag_name(flag_name)
77 , _list_name(nullptr)
78 , _list(list)
79 , _i(i)
80 , _one_list_iterator(one_list_only)
81 {
82 }
83
84 public:
86 iterator(const iterator&) = default;
87
89 struct Flag {
90 const char* flag_name;
91 const char* list_name;
92#ifdef INK_ENABLE_STL
97 friend std::ostream& operator<<(std::ostream& os, const Flag& flag)
98 {
99 os << flag.list_name << "(" << flag.flag_name << ")";
100 return os;
101 }
102#endif
103 };
104
106 Flag operator*() const { return Flag{_flag_name, _list_name}; };
107
109 iterator& operator++()
110 {
111 _list.next(_flag_name, _list_name, _i, _one_list_iterator);
112 return *this;
113 }
114
118 bool operator!=(const iterator& itr) const { return itr._i != _i; }
119
123 bool operator==(const iterator& itr) const { return itr._i == _i; }
124
125 iterator& operator=(const iterator&) = delete;
126 };
127
128
129#ifdef __GNUC__
130# pragma GCC diagnostic push
131# pragma GCC diagnostic ignored "-Wunused-parameter"
132#else
133# pragma warning(push)
134// non functional prototypes do not need the argument.
135# pragma warning(disable : 4100)
136#endif
137
139 virtual bool contains(const char* flag) const
140 {
141 inkAssert(false, "Not implemented function from interfaces is called!");
142 return false;
143 };
144
146 virtual void add(const char* flag)
147 {
148 inkAssert(false, "Not implemented function from interface is called!");
149 };
150
152 virtual void remove(const char* flag)
153 {
154 inkAssert(false, "Not implemented function from interface is called!");
155 };
156
158 virtual iterator begin() const
159 {
160 inkAssert(false, "Not implemented function from interface is called!");
161 return new_iterator(nullptr, -1);
162 };
163
165 virtual iterator begin(const char* list_name) const
166 {
167 inkAssert(false, "Not implemented function from interface is called!");
168 return new_iterator(nullptr, -1);
169 }
170
172 virtual iterator end() const
173 {
174 inkAssert(false, "Not implemented function from interface is called!");
175 return new_iterator(nullptr, -1);
176 };
177
178private:
179 friend iterator;
180
181 virtual void
182 next(const char*& flag_name, const char*& list_name, int& i, bool _one_list_iterator) const
183 {
184 inkAssert(false, "Not implemented funciton from interface is called!");
185 };
186
187#ifdef __GNUC__
188# pragma GCC diagnostic pop
189#else
190# pragma warning(pop)
191#endif
192
193protected:
195 iterator new_iterator(const char* flag_name, int i, bool one_list_only = false) const
196 {
197 return iterator(flag_name, *this, i, one_list_only);
198 }
199
201 list_interface(internal::list_table& table, int list)
202 : _list_table{&table}
203 , _list{list}
204 {
205 }
206
208 internal::list_table* _list_table;
210 int _list;
211};
212
213} // 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:60
iterator(const iterator &)=default
copy constructor.
iterator & operator++()
continue iterator to next value
Definition list.h:109
bool operator!=(const iterator &itr) const
checks if iterator points not to the same element
Definition list.h:118
Flag operator*() const
access value the iterator is pointing to
Definition list.h:106
bool operator==(const iterator &itr) const
checks if iterator points to the same element
Definition list.h:123
virtual bool contains(const char *flag) const
checks if a flag is contained in the list
Definition list.h:139
virtual iterator begin() const
begin iterator for contained flags in list
Definition list.h:158
virtual list_interface & operator=(const list_interface &)=default
copy assigment operator.
virtual void remove(const char *flag)
removes a flag from list
Definition list.h:152
virtual void add(const char *flag)
add a flag to list
Definition list.h:146
virtual iterator begin(const char *list_name) const
returns a iterator over elements of the given list
Definition list.h:165
virtual iterator end() const
end iterator for contained flags in list
Definition list.h:172
#define inkAssert(condition, text,...)
Compile argument agnostic assert macro.
Definition system.h:58
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:89
const char * flag_name
name of the flag
Definition list.h:90
const char * list_name
name of the list
Definition list.h:91
friend std::ostream & operator<<(std::ostream &os, const Flag &flag)
serelization operator
Definition list.h:97