ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Macros | Functions
SimpleSelector.c File Reference
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <Objectively/Hash.h>
#include <Objectively/MutableArray.h>
#include <Objectively/String.h>
#include "SimpleSelector.h"

Go to the source code of this file.

Macros

#define _Class   _SimpleSelector
 

Functions

Class * _SimpleSelector (void)
 
static void dealloc (Object *self)
 
static String * description (const Object *self)
 
static int hash (const Object *self)
 
static void initialize (Class *clazz)
 
static SimpleSelectorinitWithPattern (SimpleSelector *self, const char *pattern)
 
static _Bool isEqual (const Object *self, const Object *other)
 
static Array * parse (const char *sequence)
 
static SimpleSelectorType simpleSelectorType (const char c)
 

Macro Definition Documentation

◆ _Class

#define _Class   _SimpleSelector

Definition at line 34 of file SimpleSelector.c.

Function Documentation

◆ _SimpleSelector()

Class * _SimpleSelector ( void  )

Definition at line 200 of file SimpleSelector.c.

200 {
201 static Class *clazz;
202 static Once once;
203
204 do_once(&once, {
205 clazz = _initialize(&(const ClassDef) {
206 .name = "SimpleSelector",
207 .superclass = _Object(),
208 .instanceSize = sizeof(SimpleSelector),
209 .interfaceOffset = offsetof(SimpleSelector, interface),
210 .interfaceSize = sizeof(SimpleSelectorInterface),
212 });
213 });
214
215 return clazz;
216}
static void initialize(Class *clazz)
The SimpleSelector type.

◆ dealloc()

static void dealloc ( Object *  self)
static
See also
Object::dealloc(Object *)

Definition at line 41 of file SimpleSelector.c.

41 {
42
43 SimpleSelector *this = (SimpleSelector *) self;
44
45 free(this->pattern);
46
47 super(Object, self, dealloc);
48}
static void dealloc(Object *self)

◆ description()

static String * description ( const Object *  self)
static
See also
Object::description(const Object *)

Definition at line 53 of file SimpleSelector.c.

53 {
54
55 const SimpleSelector *this = (SimpleSelector *) self;
56
57 return str(this->pattern);
58}

◆ hash()

static int hash ( const Object *  self)
static
See also
Object::hash(const Object *)

Definition at line 63 of file SimpleSelector.c.

63 {
64
65 SimpleSelector *this = (SimpleSelector *) self;
66
67 return HashForCString(HASH_SEED, this->pattern);
68}

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

Definition at line 185 of file SimpleSelector.c.

185 {
186
187 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
188 ((ObjectInterface *) clazz->interface)->description = description;
189 ((ObjectInterface *) clazz->interface)->hash = hash;
190 ((ObjectInterface *) clazz->interface)->isEqual = isEqual;
191
192 ((SimpleSelectorInterface *) clazz->interface)->initWithPattern = initWithPattern;
193 ((SimpleSelectorInterface *) clazz->interface)->parse = parse;
194}
static String * description(const Object *self)
static _Bool isEqual(const Object *self, const Object *other)
static int hash(const Object *self)
Array * parse(const char *rules)
Parses the null-terminated C string of Selector rules into an Array of Selectors.
Definition: Selector.c:274
Array * parse(const char *sequence)
Definition: Selector.c:274
SimpleSelector * initWithPattern(SimpleSelector *self, const char *pattern)
Initializes this SimpleSelector.

◆ initWithPattern()

static SimpleSelector * initWithPattern ( SimpleSelector self,
const char *  pattern 
)
static

Definition at line 96 of file SimpleSelector.c.

96 {
97
98 self = (SimpleSelector *) super(Object, self, init);
99 if (self) {
100
101 self->pattern = strtrim(pattern);
102 assert(self->pattern);
103
104 assert(strlen(self->pattern));
105 }
106
107 return self;
108}
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
char * pattern
The pattern, as provided by the user.

◆ isEqual()

static _Bool isEqual ( const Object *  self,
const Object *  other 
)
static
See also
Object::isEqual(const Object *, const Object *)

Definition at line 73 of file SimpleSelector.c.

73 {
74
75 if (super(Object, self, isEqual, other)) {
76 return true;
77 }
78
79 if (other && $(other, isKindOfClass, _SimpleSelector())) {
80
81 const SimpleSelector *this = (SimpleSelector *) self;
82 const SimpleSelector *that = (SimpleSelector *) other;
83
84 return strcmp(this->pattern, that->pattern) == 0;
85 }
86
87 return false;
88}
Class * _SimpleSelector(void)
The SimpleSelector archetype.

◆ parse()

static Array * parse ( const char *  sequence)
static

Definition at line 134 of file SimpleSelector.c.

134 {
135
136 MutableArray *simpleSelectors = $$(MutableArray, arrayWithCapacity, 4);
137 assert(simpleSelectors);
138
139 if (sequence) {
140
141 const char *c = sequence;
142 const char *delim = sequence;
143 while (*c) {
144 const size_t size = strcspn(c, "*.#:");
145 if (size || *c == '*') {
146
147 char *pattern;
148 if (*c == '*') {
149 pattern = strdup("*");
150 assert(pattern);
151 } else {
152 pattern = calloc(1, size + 1);
153 assert(pattern);
154
155 strncpy(pattern, c, size);
156 }
157
158 SimpleSelector *simpleSelector = $(alloc(SimpleSelector), initWithPattern, pattern);
159 assert(simpleSelector);
160
161 simpleSelector->type = simpleSelectorType(*delim);
162 assert(simpleSelector->type);
163
164 delim = c + size;
165
166 $(simpleSelectors, addObject, simpleSelector);
167
168 release(simpleSelector);
169 free(pattern);
170 }
171
172 c += size;
173 c += strspn(c, "*.#:");
174 }
175 }
176
177 return (Array *) simpleSelectors;
178}
static SimpleSelectorType simpleSelectorType(const char c)
SDL_Size size(const Image *self)
Definition: Image.c:181
SimpleSelectorType type
The SimpleSelectorType.

◆ simpleSelectorType()

static SimpleSelectorType simpleSelectorType ( const char  c)
static
Returns
The SimpleSelectorType for the given character.

Definition at line 113 of file SimpleSelector.c.

113 {
114 switch (c) {
115 case '\0':
117 case '*':
119 case '#':
121 case '.':
123 case ':':
125 default:
127 }
128}
@ SimpleSelectorTypePseudo
@ SimpleSelectorTypeId
@ SimpleSelectorTypeClass
@ SimpleSelectorTypeUniversal
@ SimpleSelectorTypeType
@ SimpleSelectorTypeNone