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 INK_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
55 {
56 const char* _flag_name;
57 const char* _list_name;
58 const list_interface& _list;
59 int _i;
60 bool _one_list_iterator;
61 friend list_interface;
62#ifdef INK_BUILD_CLIB
63 friend int ::ink_list_flags(const HInkList*, InkListIter*);
64 friend int ::ink_list_flags_from(const HInkList*, const char*, InkListIter*);
65 friend int ::ink_list_iter_next(InkListIter* self);
66#endif
67
68 protected:
71 const char* flag_name, const list_interface& list, size_t i, bool one_list_only = false
72 )
73 : _flag_name(flag_name)
74 , _list(list)
75 , _i(i)
76 , _one_list_iterator(one_list_only)
77 {
78 }
79
80 public:
82 struct Flag {
83 const char* flag_name;
84 const char* list_name;
85#ifdef INK_ENABLE_STL
90 friend std::ostream& operator<<(std::ostream& os, const Flag& flag)
91 {
92 os << flag.list_name << "(" << flag.flag_name << ")";
93 return os;
94 }
95#endif
96 };
97
99 Flag operator*() const { return Flag{ _flag_name, _list_name }; };
100
103 {
104 _list.next(_flag_name, _list_name, _i, _one_list_iterator);
105 return *this;
106 }
107
111 bool operator!=(const iterator& itr) const { return itr._i != _i; }
112
116 bool operator==(const iterator& itr) const { return itr._i == _i; }
117 };
118
120 virtual bool contains(const char* flag) const
121 {
122 inkAssert(false, "Not implemented function from interfaces is called!");
123 return false;
124 };
125
127 virtual void add(const char* flag)
128 {
129 inkAssert(false, "Not implemented function from interface is called!");
130 };
131
133 virtual void remove(const char* flag)
134 {
135 inkAssert(false, "Not implemented function from interface is called!");
136 };
137
139 virtual iterator begin() const
140 {
141 inkAssert(false, "Not implemented function from interface is called!");
142 return new_iterator(nullptr, -1);
143 };
144
146 virtual iterator begin(const char* list_name) const
147 {
148 inkAssert(false, "Not implemented function from interface is called!");
149 return new_iterator(nullptr, -1);
150 }
151
153 virtual iterator end() const
154 {
155 inkAssert(false, "Not implemented function from interface is called!");
156 return new_iterator(nullptr, -1);
157 };
158
159private:
160 friend iterator;
161
162 virtual void
163 next(const char*& flag_name, const char*& list_name, int& i, bool _one_list_iterator) const
164 {
165 inkAssert(false, "Not implemented funciton from interface is called!");
166 };
167
168protected:
170 iterator new_iterator(const char* flag_name, int i, bool one_list_only = false) const
171 {
172 return iterator(flag_name, *this, i, one_list_only);
173 }
174
176 list_interface(internal::list_table& table, int list)
177 : _list_table{&table}
178 , _list{list}
179 {
180 }
181
183 internal::list_table* _list_table;
185 int _list;
186};
187} // 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:55
iterator & operator++()
continue iterator to next value
Definition list.h:102
bool operator!=(const iterator &itr) const
checks if iterator points not to the same element
Definition list.h:111
Flag operator*() const
access value the iterator is pointing to
Definition list.h:99
bool operator==(const iterator &itr) const
checks if iterator points to the same element
Definition list.h:116
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:120
virtual iterator begin() const
begin iterator for contained flags in list
Definition list.h:139
virtual void remove(const char *flag)
removes a flag from list
Definition list.h:133
virtual void add(const char *flag)
add a flag to list
Definition list.h:127
virtual iterator begin(const char *list_name) const
returns a iterator over elements of the given list
Definition list.h:146
virtual iterator end() const
end iterator for contained flags in list
Definition list.h:153
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:125
contains flag data
Definition list.h:82
const char * flag_name
name of the flag
Definition list.h:83
const char * list_name
name of the list
Definition list.h:84
friend std::ostream & operator<<(std::ostream &os, const Flag &flag)
serelization operator
Definition list.h:90