34#define _Class _Resource
55#pragma mark - Resource
108 self->
name = strdup(name);
123 for (
size_t i = 0; i < resourceProviders->
count &&
data == NULL; i++) {
130 for (
size_t i = 0; i < resourcePaths->
count &&
data == NULL; i++) {
136 if (stat(path->
chars, &s) == 0 && S_ISREG(s.st_mode)) {
188#pragma mark - Class lifecycle
217 const char *env = getenv(
"OBJECTIVELY_RESOURCE_PATH");
223 for (
size_t i = 0; i < paths->
count; i++) {
250 .interfaceOffset = offsetof(
Resource, interface),
251 .interfaceSize =
sizeof(ResourceInterface),
static ident objectAtIndex(const Array *self, size_t index)
static void removeObject(Array *self, const ident obj)
static void addObject(Array *self, const ident obj)
static Array * init(Array *self)
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
ident retain(ident obj)
Atomically increment the given Object's reference count.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
static Data * dataWithContentsOfFile(const char *path)
static Data * dataWithBytes(const uint8_t *bytes, size_t length)
static Pointer * initWithPointer(Pointer *self, ident pointer, Consumer destroy)
Pointers provide Object encapsulation for raw C pointers.
static void removeResourcePath(const char *path)
static void destroy(Class *clazz)
static Array * _resourcePaths
static void removeResourceProvider(ResourceProvider provider)
static void addResourceProvider(ResourceProvider provider)
static Resource * initWithName(Resource *self, const char *name)
static void dealloc(Object *self)
static Array * _resourceProviders
static void initialize(Class *clazz)
static Resource * resourceWithName(const char *name)
static Resource * initWithBytes(Resource *self, const uint8_t *bytes, size_t length, const char *name)
static void addResourcePath(const char *path)
static Resource * initWithData(Resource *self, Data *data, const char *name)
Resources provide an abstraction for file and stream resources.
Data *(* ResourceProvider)(const char *name)
Applications may specify a provider function for loading via file system abstractions.
String * str(const char *fmt,...)
static String * stringWithCharacters(const char *chars)
static Array * componentsSeparatedByCharacters(const String *self, const char *chars)
#define do_once(once, block)
Executes the given block at most one time.
size_t count
The count of elements.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Object is the root Class of The Objectively Class hierarchy.
Pointers provide Object encapsulation for raw C pointers.
ident pointer
The backing pointer.
Resources provide an abstraction for file and stream resources.
Resource * initWithData(Resource *self, Data *data)
void removeResourcePath(const char *path)
Removes the specified Resource path.
Data * data
The resource data.
Resource * initWithName(Resource *self, const char *name)
Initializes this Resource with the specified name.
char * name
The resource name.
char * chars
The backing null-terminated UTF-8 encoded character array.