1#ifndef HALIDE_RUNTIME_STRING_TABLE_H
2#define HALIDE_RUNTIME_STRING_TABLE_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 count);
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 contents.
resize(user_context, capacity);
92 for (
size_t n = 0; n < contents.
size(); ++n) {
94 contents.
assign(user_context, n, storage_ptr);
99 for (
size_t n = 0; n < contents.
size(); ++n) {
102 contents.
assign(user_context, n,
nullptr);
104 contents.
clear(user_context);
105 pointers.
clear(user_context);
109 for (
size_t n = 0; n < contents.
size(); ++n) {
112 contents.
assign(user_context, n,
nullptr);
114 contents.
destroy(user_context);
115 pointers.
destroy(user_context);
119 if (index < pointers.
size()) {
120 return static_cast<const char *
>(pointers[index]);
126 resize(user_context, count);
127 for (
size_t n = 0; n < count && n < contents.
size(); ++n) {
129 storage_ptr->
assign(user_context, array[n]);
130 pointers.
assign(user_context, n, storage_ptr->
data());
138 if (index < contents.
size()) {
140 storage_ptr->
assign(user_context, str, length);
141 pointers.
assign(user_context, index, storage_ptr->
data());
147 storage_ptr->
assign(user_context, str, length);
148 contents.
append(user_context, storage_ptr);
149 pointers.
append(user_context, storage_ptr->
data());
154 storage_ptr->
assign(user_context, str, length);
155 contents.
prepend(user_context, storage_ptr);
156 pointers.
prepend(user_context, storage_ptr->
data());
164 size_t delim_length =
strlen(delim);
165 size_t total_length =
strlen(str);
167 if (entry_count < 1) {
171 resize(user_context, entry_count);
175 const char *ptr = str;
177 size_t ptr_offset = ptr - str;
178 const char *next_delim =
strstr(ptr, delim);
179 size_t token_length = (next_delim ==
nullptr) ? (total_length - ptr_offset) : (next_delim - ptr);
180 if (token_length > 0 && index < contents.
size()) {
182 storage_ptr->
assign(user_context, ptr, token_length);
183 pointers.
assign(user_context, index, storage_ptr->
data());
186 ptr = (next_delim !=
nullptr) ? (next_delim + delim_length) :
nullptr;
195 for (
size_t n = 0; n < contents.
size(); ++n) {
206 return reinterpret_cast<const char **
>(pointers.
data());
This file declares the routines used by Halide internally in its runtime.
const SystemMemoryAllocatorFns & current_allocator() const
void clear(void *user_context)
void prepend(void *user_context, const void *entry_ptr)
void destroy(void *user_context)
void resize(void *user_context, size_t entry_count, bool realloc=true)
void append(void *user_context, const void *entry_ptr)
void assign(void *user_context, size_t index, const void *entry_ptr)
void assign(void *user_context, char ch)
static const SystemMemoryAllocatorFns & default_allocator()
const char * data() const
static StringStorage * create(void *user_context, const SystemMemoryAllocatorFns &ma)
bool contains(const char *str) const
static void destroy(void *user_context, StringStorage *string_storage)
void append(void *user_context, const char *str, size_t length=0)
StringTable(const StringTable &)=delete
const char ** data() const
size_t parse(void *user_context, const char *str, const char *delim)
void assign(void *user_context, size_t index, const char *str, size_t length=0)
void destroy(void *user_context)
const char * operator[](size_t index) const
void resize(void *user_context, size_t capacity)
void clear(void *user_context)
StringTable & operator=(const StringTable &)=delete
void prepend(void *user_context, const char *str, size_t length=0)
void fill(void *user_context, const char **array, size_t count)
bool contains(const char *str) const
size_t strlen(const char *string)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
const char * strstr(const char *, const char *)
static size_t count_tokens(const char *str, const char *delim)
static bool is_empty(const char *str)