1#ifndef HALIDE_RUNTIME_STRING_STORAGE_H
2#define HALIDE_RUNTIME_STRING_STORAGE_H
33 const char *ptr = str;
34 size_t delim_length =
strlen(delim);
36 const char *next_delim =
strstr(ptr, delim);
37 ptr = (next_delim !=
nullptr) ? (next_delim + delim_length) :
nullptr;
44 static bool contains(
const char *s1,
const char *s2,
size_t n) {
48 char starts_with = *s2;
49 for (
size_t length =
strlen(s2); length <= n; n--, s1++) {
50 if (*s1 == starts_with) {
51 for (
size_t i = 1; i <= length; i++) {
65 const char *ptr = str;
72 static size_t copy_up_to(
char *dst,
const char *src,
size_t max_chars) {
95 void destroy(
void *user_context);
101 bool contains(
const char *str)
const;
105 void assign(
void *user_context,
char ch);
106 void assign(
void *user_context,
const char *str,
size_t length = 0);
107 void append(
void *user_context,
char ch);
108 void append(
void *user_context,
const char *str,
size_t length = 0);
109 void prepend(
void *user_context,
char ch);
110 void prepend(
void *user_context,
const char *str,
size_t length = 0);
111 void clear(
void *user_context);
115 const char *
data()
const;
125 : contents(user_context, {
sizeof(char), 32, 32}, sma) {
127 contents.reserve(user_context, capacity);
140 if (result ==
nullptr) {
141 halide_error(user_context,
"StringStorage: Failed to create instance! Out of memory!\n");
145 result->
initialize(user_context, 32, system_allocator);
152 instance->
destroy(user_context);
154 system_allocator.
deallocate(user_context, instance);
158 if (&other !=
this) {
165 if (contents.
empty()) {
168 const char *this_str =
static_cast<const char *
>(contents.
data());
173 if (contents.
empty()) {
176 if (other.contents.
empty()) {
179 const char *this_str =
static_cast<const char *
>(contents.
data());
180 const char *other_str =
static_cast<const char *
>(other.contents.
data());
185 if (contents.
size() != other.contents.
size()) {
188 const char *this_str =
static_cast<const char *
>(contents.
data());
189 const char *other_str =
static_cast<const char *
>(other.contents.
data());
190 return strncmp(this_str, other_str, contents.
size()) == 0;
194 return !(*
this == other);
205 char *ptr =
static_cast<char *
>(contents[0]);
230 size_t new_length = old_length +
length;
231 reserve(user_context, new_length);
238 size_t new_length = old_length + 1;
239 reserve(user_context, new_length);
240 contents.
insert(user_context, old_length, &ch, 1);
252 size_t new_length = old_length +
length;
253 reserve(user_context, new_length);
260 size_t new_length = old_length + 1;
261 reserve(user_context, new_length);
262 contents.
prepend(user_context, &ch);
268 char *end_ptr =
static_cast<char *
>(contents[
length]);
271 halide_error(user_context,
"StringStorage: Failed to terminate string! Out of bounds!\n");
276 contents.
clear(user_context);
281 contents.
initialize(user_context, {
sizeof(char), 32, 32}, sma);
282 reserve(user_context, capacity);
287 contents.
destroy(user_context);
295 return static_cast<const char *
>(contents.
data());
This file declares the routines used by Halide internally in its runtime.
void halide_error(void *user_context, const char *)
Halide calls this function on runtime errors (for example bounds checking failures).
void destroy(void *user_context)
void clear(void *user_context)
void resize(void *user_context, size_t entry_count, bool realloc=true)
void replace(void *user_context, size_t index, const void *array, size_t array_size)
void prepend(void *user_context, const void *entry_ptr)
void insert(void *user_context, size_t index, const void *entry_ptr)
void initialize(void *user_context, const Config &cfg, const SystemMemoryAllocatorFns &sma=default_allocator())
static const SystemMemoryAllocatorFns & default_allocator()
const SystemMemoryAllocatorFns & current_allocator() const
bool is_valid(size_t index) const
void reserve(void *user_context, size_t capacity, bool free_existing=false)
const SystemMemoryAllocatorFns & current_allocator() const
void assign(void *user_context, char ch)
void prepend(void *user_context, char ch)
StringStorage(void *user_context=nullptr, uint32_t capacity=0, const SystemMemoryAllocatorFns &sma=default_allocator())
StringStorage & operator=(const StringStorage &other)
static const SystemMemoryAllocatorFns & default_allocator()
bool operator==(const StringStorage &other) const
const char * data() const
void reserve(void *user_context, size_t length)
bool operator!=(const StringStorage &other) const
StringStorage(const StringStorage &other)=default
void initialize(void *user_context, uint32_t capacity=0, const SystemMemoryAllocatorFns &sma=default_allocator())
static StringStorage * create(void *user_context, const SystemMemoryAllocatorFns &ma)
bool contains(const char *str) const
void clear(void *user_context)
void append(void *user_context, char ch)
void terminate(void *user_context, size_t length)
static void destroy(void *user_context, StringStorage *string_storage)
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.
int strncmp(const char *s, const char *t, size_t n)
void * memcpy(void *s1, const void *s2, size_t n)
unsigned __INT32_TYPE__ uint32_t
#define halide_abort_if_false(user_context, cond)
const char * strstr(const char *, const char *)
static size_t count_tokens(const char *str, const char *delim)
static bool contains(const char *s1, const char *s2, size_t n)
static size_t count_length(const char *str, size_t max_chars)
static bool is_empty(const char *str)
static size_t copy_up_to(char *dst, const char *src, size_t max_chars)
DeallocateSystemFn deallocate
AllocateSystemFn allocate