1 #ifndef HALIDE_RUNTIME_STRING_TABLE_H
2 #define HALIDE_RUNTIME_STRING_TABLE_H
4 #include "../HalideRuntime.h"
26 void resize(
void *user_context,
size_t capacity);
27 void destroy(
void *user_context);
28 void clear(
void *user_context);
31 void fill(
void *user_context,
const char **array,
size_t coun);
34 void assign(
void *user_context,
size_t index,
const char *str,
size_t length = 0);
37 void append(
void *user_context,
const char *str,
size_t length = 0);
40 void prepend(
void *user_context,
const char *str,
size_t length = 0);
43 size_t parse(
void *user_context,
const char *str,
const char *delim);
49 const char **
data()
const;
52 bool contains(
const char *str)
const;
55 return contents.
size();
66 : contents(nullptr, 0, sma),
67 pointers(nullptr, 0, sma) {
72 : contents(user_context, capacity, sma),
73 pointers(user_context, capacity, sma) {
75 resize(user_context, capacity);
80 : contents(user_context, count, sma),
81 pointers(user_context, count, sma) {
82 fill(user_context, array, count);
90 pointers.
resize(user_context, capacity);
91 while (contents.
size() < capacity) {
93 contents.
append(user_context, storage_ptr);
98 for (
size_t n = 0; n < contents.
size(); ++n) {
101 contents.
assign(user_context, n,
nullptr);
103 contents.
clear(user_context);
104 pointers.
clear(user_context);
108 for (
size_t n = 0; n < contents.
size(); ++n) {
111 contents.
assign(user_context, n,
nullptr);
113 contents.
destroy(user_context);
114 pointers.
destroy(user_context);
118 if (index < pointers.
size()) {
119 return static_cast<const char *
>(pointers[index]);
125 resize(user_context, count);
126 for (
size_t n = 0; n < count && n < contents.
size(); ++n) {
128 storage_ptr->
assign(user_context, array[n]);
129 pointers.
assign(user_context, n, storage_ptr->
data());
137 if (index < contents.
size()) {
139 storage_ptr->
assign(user_context, str, length);
140 pointers.
assign(user_context, index, storage_ptr->
data());
146 storage_ptr->
assign(user_context, str, length);
147 contents.
append(user_context, storage_ptr);
148 pointers.
append(user_context, storage_ptr->
data());
153 storage_ptr->
assign(user_context, str, length);
154 contents.
prepend(user_context, storage_ptr);
155 pointers.
prepend(user_context, storage_ptr->
data());
163 size_t delim_length =
strlen(delim);
164 size_t total_length =
strlen(str);
166 if (entry_count < 1) {
170 resize(user_context, entry_count);
174 const char *ptr = str;
176 size_t ptr_offset = ptr - str;
177 const char *next_delim =
strstr(ptr, delim);
178 size_t token_length = (next_delim ==
nullptr) ? (total_length - ptr_offset) : (next_delim - ptr);
179 if (token_length > 0 && index < contents.
size()) {
181 storage_ptr->
assign(user_context, ptr, token_length);
182 pointers.
assign(user_context, index, storage_ptr->
data());
185 ptr = (next_delim !=
nullptr) ? (next_delim + delim_length) :
nullptr;
194 for (
size_t n = 0; n < contents.
size(); ++n) {
205 return reinterpret_cast<const char **
>(pointers.
data());
214 #endif // HALIDE_RUNTIME_STRING_STORAGE_H