ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Public Member Functions | Static Public Member Functions | Data Fields | Protected Attributes
Stylesheet Struct Reference

Stylesheets are comprised of Selectors and Styles. More...

#include <Stylesheet.h>

Inheritance diagram for Stylesheet:

Public Member Functions

Class * _Stylesheet (void)
 The Stylesheet archetype. More...
 
StylesheetdefaultStylesheet (void)
 
StylesheetinitWithCharacters (Stylesheet *self, const char *chars)
 Initializes this Stylesheet with the given CSS definitions. More...
 
StylesheetinitWithData (Stylesheet *self, const Data *data)
 Initializes this Stylesheet with the CSS definitions in data. More...
 
StylesheetinitWithResource (Stylsheet *self, const Resource *resource)
 Initializes this Stylsheet with the CSS definitions in resource. More...
 
StylesheetinitWithResourceName (Stylsheet *self, const char *name)
 Initializes this Stylsheet with the Resource by the specified name. More...
 
StylesheetinitWithString (Stylesheet *self, const String *string)
 Initializes this Stylesheet with the CSS definitions in string. More...
 
StylesheetstylesheetWithCharacters (const char *chars)
 Instantiates a new Stylesheet with the given CSS definitions. More...
 
StylesheetstylesheetWithCharacters (const Data *data)
 Instantiates a new Stylesheet with the given CSS Data. More...
 
StylesheetstylesheetWithResource (const Resource *resource)
 Instantiates a new Stylesheet with the given CSS Resource. More...
 
StylesheetstylesheetWithResourceName (const char *name)
 Instantiates a new Stylesheet with the CSS Resource by the specified name. More...
 
StylesheetstylesheetWithString (const String *string)
 Instantiates a new Stylesheet with the given CSS String. More...
 

Static Public Member Functions

StylesheetstylesheetWithCharacters (const char *chars)
 Instantiates a new Stylesheet with the given CSS definitions. More...
 
StylesheetstylesheetWithCharacters (const Data *data)
 Instantiates a new Stylesheet with the given CSS Data. More...
 

Data Fields

Object object
 The superclass. More...
 
Array * selectors
 The Selectors, ordered by specificity. More...
 
Array * styles
 The Styles, keyed by Selector. More...
 

Protected Attributes

StylesheetInterface * interface
 The interface. More...
 

Detailed Description

Stylesheets are comprised of Selectors and Styles.

Definition at line 44 of file Stylesheet.h.

Member Function Documentation

◆ _Stylesheet()

Class * _Stylesheet ( void  )

The Stylesheet archetype.

Returns
The Stylesheet Class.

Definition at line 277 of file Stylesheet.c.

277 {
278 static Class *clazz;
279 static Once once;
280
281 do_once(&once, {
282 clazz = _initialize(&(const ClassDef) {
283 .name = "Stylesheet",
284 .superclass = _Object(),
285 .instanceSize = sizeof(Stylesheet),
286 .interfaceOffset = offsetof(Stylesheet, interface),
287 .interfaceSize = sizeof(StylesheetInterface),
289 .destroy = destroy,
290 });
291 });
292
293 return clazz;
294}
static void destroy(Class *clazz)
Definition: Stylesheet.c:269
static void initialize(Class *clazz)
Definition: Stylesheet.c:247
Stylesheets are comprised of Selectors and Styles.
Definition: Stylesheet.h:44
StylesheetInterface * interface
The interface.
Definition: Stylesheet.h:55

◆ defaultStylesheet()

Stylesheet * defaultStylesheet ( void  )
Returns
The default Stylesheet.

Definition at line 95 of file Stylesheet.c.

95 {
96 static Once once;
97
98 do_once(&once, {
99 _defaultStylesheet = $$(Stylesheet, stylesheetWithCharacters, (char *) stylesheet_css);
100 assert(_defaultStylesheet);
101 });
102
103 return _defaultStylesheet;
104}
static Stylesheet * _defaultStylesheet
Definition: Stylesheet.c:89
Stylesheet * stylesheetWithCharacters(const char *chars)
Instantiates a new Stylesheet with the given CSS definitions.
Definition: Stylesheet.c:206

◆ initWithCharacters()

Stylesheet * initWithCharacters ( Stylesheet self,
const char *  chars 
)

Initializes this Stylesheet with the given CSS definitions.

Parameters
selfThe Stylesheet.
charsThe null-terminated C string of CSS definitions.
Returns
The initialized Stylesheet, or NULL on error.
Remarks
Designated initializer.

Definition at line 124 of file Stylesheet.c.

124 {
125
126 self = (Stylesheet *) super(Object, self, init);
127 if (self) {
128
129 self->styles = $$(Style, parse, chars);
130 assert(self->styles);
131
132 MutableArray *selectors = $$(MutableArray, array);
133 assert(selectors);
134
135 $(self->styles, reduce, selectorsReducer, selectors, NULL);
136
137 self->selectors = $((Array *) selectors, sortedArray, selectorsComparator);
138 assert(self->selectors);
139
140 release(selectors);
141 }
142
143 return self;
144}
static View * init(View *self)
Definition: Box.c:67
static Array * parse(const char *rules)
Definition: Selector.c:274
static ident selectorsReducer(const ident obj, ident accumulator, ident data)
Definition: Stylesheet.c:106
static Order selectorsComparator(const ident a, const ident b)
Comparator for Selector sorting.
Definition: Stylesheet.c:116
The Style type.
Definition: Style.h:43
Array * styles
The Styles, keyed by Selector.
Definition: Stylesheet.h:65
Array * selectors
The Selectors, ordered by specificity.
Definition: Stylesheet.h:60

◆ initWithData()

Stylesheet * initWithData ( Stylesheet self,
const Data *  data 
)

Initializes this Stylesheet with the CSS definitions in data.

Parameters
selfThe Stylesheet.
dataThe Data containing CSS definitions.
Returns
The initialized Stylesheet, or NULL on error.

Definition at line 150 of file Stylesheet.c.

150 {
151
152 assert(data);
153
154 String *string = $$(String, stringWithData, data, STRING_ENCODING_UTF8);
155 assert(string);
156
157 self = $(self, initWithString, string);
158
159 release(string);
160 return self;
161}
Stylesheet * initWithString(Stylesheet *self, const String *string)
Initializes this Stylesheet with the CSS definitions in string.
Definition: Stylesheet.c:195

◆ initWithResource()

Stylesheet * initWithResource ( Stylsheet *  self,
const Resource *  resource 
)

Initializes this Stylsheet with the CSS definitions in resource.

Parameters
selfThe Stylesheet.
resourceThe Resource containing CSS definitions.
Returns
The initialized Stylesheet, or NULL on error.

◆ initWithResourceName()

Stylesheet * initWithResourceName ( Stylsheet *  self,
const char *  name 
)

Initializes this Stylsheet with the Resource by the specified name.

Parameters
selfThe Stylesheet.
nameThe name of a Resource containing CSS definitions.
Returns
The initialized Stylesheet, or NULL on error.

◆ initWithString()

Stylesheet * initWithString ( Stylesheet self,
const String *  string 
)

Initializes this Stylesheet with the CSS definitions in string.

Parameters
selfThe Stylesheet.
stringThe String containing CSS definitions.
Returns
The initialized Stylesheet, or NULL on error.

Definition at line 195 of file Stylesheet.c.

195 {
196
197 assert(string);
198
199 return $(self, initWithCharacters, string->chars);
200}
Stylesheet * initWithCharacters(Stylesheet *self, const char *chars)
Initializes this Stylesheet with the given CSS definitions.
Definition: Stylesheet.c:124

◆ stylesheetWithCharacters() [1/4]

Stylesheet * stylesheetWithCharacters ( const char *  chars)

Instantiates a new Stylesheet with the given CSS definitions.

Parameters
charsThe null-terminated C string of CSS definitions.
Returns
The new Stylesheet, or NULL on error.

Definition at line 206 of file Stylesheet.c.

206 {
207 return $(alloc(Stylesheet), initWithCharacters, chars);
208}

◆ stylesheetWithCharacters() [2/4]

Stylesheet * stylesheetWithCharacters ( const char *  chars)
static

Instantiates a new Stylesheet with the given CSS definitions.

Parameters
charsThe null-terminated C string of CSS definitions.
Returns
The new Stylesheet, or NULL on error.

Definition at line 206 of file Stylesheet.c.

206 {
207 return $(alloc(Stylesheet), initWithCharacters, chars);
208}

◆ stylesheetWithCharacters() [3/4]

Stylesheet * stylesheetWithCharacters ( const Data *  data)

Instantiates a new Stylesheet with the given CSS Data.

Parameters
dataThe Data containing CSS definitions.
Returns
The new Stylesheet, or NULL on error.

◆ stylesheetWithCharacters() [4/4]

Stylesheet * stylesheetWithCharacters ( const Data *  data)
static

Instantiates a new Stylesheet with the given CSS Data.

Parameters
dataThe Data containing CSS definitions.
Returns
The new Stylesheet, or NULL on error.

◆ stylesheetWithResource()

Stylesheet * stylesheetWithResource ( const Resource *  resource)

Instantiates a new Stylesheet with the given CSS Resource.

Parameters
resourceThe Resource containing CSS definitions.
Returns
The new Stylesheet, or NULL on error.

Definition at line 222 of file Stylesheet.c.

222 {
223 return $(alloc(Stylesheet), initWithResource, resource);
224}
Stylesheet * initWithResource(Stylsheet *self, const Resource *resource)
Initializes this Stylsheet with the CSS definitions in resource.

◆ stylesheetWithResourceName()

Stylesheet * stylesheetWithResourceName ( const char *  name)

Instantiates a new Stylesheet with the CSS Resource by the specified name.

Parameters
nameThe name of a Resource containing CSS definitions.
Returns
The new Stylesheet, or NULL on error.

Definition at line 230 of file Stylesheet.c.

230 {
231 return $(alloc(Stylesheet), initWithResourceName, name);
232}
Stylesheet * initWithResourceName(Stylsheet *self, const char *name)
Initializes this Stylsheet with the Resource by the specified name.

◆ stylesheetWithString()

Stylesheet * stylesheetWithString ( const String *  string)

Instantiates a new Stylesheet with the given CSS String.

Parameters
stringThe String of containing CSS definitions.
Returns
The new Stylesheet, or NULL on error.

Definition at line 238 of file Stylesheet.c.

238 {
239 return $(alloc(Stylesheet), initWithString, string);
240}

Field Documentation

◆ interface

StylesheetInterface* Stylesheet::interface
protected

The interface.

Definition at line 55 of file Stylesheet.h.

◆ object

Object Stylesheet::object

The superclass.

Definition at line 49 of file Stylesheet.h.

◆ selectors

Array* Stylesheet::selectors

The Selectors, ordered by specificity.

Definition at line 60 of file Stylesheet.h.

◆ styles

Array* Stylesheet::styles

The Styles, keyed by Selector.

Definition at line 65 of file Stylesheet.h.


The documentation for this struct was generated from the following files: