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_name(nullptr)
75 , _list(list)
76 , _i(i)
77 , _one_list_iterator(one_list_only)
78 {
79 }
80
81 public:
83 struct Flag {
84 const char* flag_name;
85 const char* list_name;
86#ifdef INK_ENABLE_STL
91 friend std::ostream& operator<<(std::ostream& os, const Flag& flag)
92 {
93 os << flag.list_name << "(" << flag.flag_name << ")";
94 return os;
95 }
96#endif
97 };
98
100 Flag operator*() const { return Flag{ _flag_name, _list_name }; };
101
104 {
105 _list.next(_flag_name, _list_name, _i, _one_list_iterator);
106 return *this;
107 }
108
112 bool operator!=(const iterator& itr) const { return itr._i != _i; }
113
117 bool operator==(const iterator& itr) const { return itr._i == _i; }
118 };
119
121 virtual bool contains(const char* flag) const
122 {
123 inkAssert(false, "Not implemented function from interfaces is called!");
124 return false;
125 };
126
128 virtual void add(const char* flag)
129 {
130 inkAssert(false, "Not implemented function from interface is called!");
131 };
132
134 virtual void remove(const char* flag)
135 {
136 inkAssert(false, "Not implemented function from interface is called!");
137 };
138
140 virtual iterator begin() const
141 {
142 inkAssert(false, "Not implemented function from interface is called!");
143 return new_iterator(nullptr, -1);
144 };
145
147 virtual iterator begin(const char* list_name) const
148 {
149 inkAssert(false, "Not implemented function from interface is called!");
150 return new_iterator(nullptr, -1);
151 }
152
154 virtual iterator end() const
155 {
156 inkAssert(false, "Not implemented function from interface is called!");
157 return new_iterator(nullptr, -1);
158 };
159
160private:
161 friend iterator;
162
163 virtual void
164 next(const char*& flag_name, const char*& list_name, int& i, bool _one_list_iterator) const
165 {
166 inkAssert(false, "Not implemented funciton from interface is called!");
167 };
168
169protected:
171 iterator new_iterator(const char* flag_name, int i, bool one_list_only = false) const
172 {
173 return iterator(flag_name, *this, i, one_list_only);
174 }
175
177 list_interface(internal::list_table& table, int list)
178 : _list_table{&table}
179 , _list{list}
180 {
181 }
182
184 internal::list_table* _list_table;
186 int _list;
187};
188} // 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:103
bool operator!=(const iterator &itr) const
checks if iterator points not to the same element
Definition list.h:112
Flag operator*() const
access value the iterator is pointing to
Definition list.h:100
bool operator==(const iterator &itr) const
checks if iterator points to the same element
Definition list.h:117
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:121
virtual iterator begin() const
begin iterator for contained flags in list
Definition list.h:140
virtual void remove(const char *flag)
removes a flag from list
Definition list.h:134
virtual void add(const char *flag)
add a flag to list
Definition list.h:128
virtual iterator begin(const char *list_name) const
returns a iterator over elements of the given list
Definition list.h:147
virtual iterator end() const
end iterator for contained flags in list
Definition list.h:154
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:127
contains flag data
Definition list.h:83
const char * flag_name
name of the flag
Definition list.h:84
const char * list_name
name of the list
Definition list.h:85
friend std::ostream & operator<<(std::ostream &os, const Flag &flag)
serelization operator
Definition list.h:91