ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
View+JSON.h File Reference

JSON data binding for Views. More...

Go to the source code of this file.

Data Structures

struct  Inlet
 Inlets enable inbound data binding of View attributes through JSON. More...
 
struct  Outlet
 Outlets enable outbound data binding of Views through JSON. More...
 

Macros

#define BindInlet(inlet, obj)   (inletBindings[(inlet)->type])(inlet, (ident) obj)
 Binds the Inlet to obj by invoking the appropriate InletBinding function.
 
#define MakeInlet(name, type, dest, data)   (Inlet) { (name), (type), (dest), (ident) (data) }
 Creates an Inlet with the specified parameters.
 
#define MakeInlets(...)
 Creates a null-termianted array of Inlets.
 
#define MakeOutlet(identifier, view)   (Outlet) { (identifier), (View **) (view) }
 Creates an Outlet with the specified parameters.
 
#define MakeOutlets(...)
 Creates a NULL-termianted array of Outlets.
 

Typedefs

typedef void(* InletBinding) (const Inlet *inlet, ident obj)
 A function pointer for Inlet binding.
 

Enumerations

enum  InletType {
  InitTypeEnd = -1 , InletTypeBool , InletTypeCharacters , InletTypeClassNames ,
  InletTypeColor , InletTypeDouble , InletTypeEnum , InletTypeFloat ,
  InletTypeFont , InletTypeImage , InletTypeInteger , InletTypePoint ,
  InletTypeRectangle , InletTypeSize , InletTypeStyle , InletTypeSubviews ,
  InletTypeView , InletTypeApplicationDefined
}
 Inlet type constants. More...
 

Functions

OBJECTIVELYMVC_EXPORT bool bindInlets (const Inlet *inlets, const Dictionary *dictionary)
 Binds each Inlet specified in inlets to the data provided in dictionary.
 

Variables

OBJECTIVELYMVC_EXPORT const InletBinding inletBindings []
 The Array of InletBindings, indexed by InletType.
 

Detailed Description

JSON data binding for Views.

Definition in file View+JSON.h.

Macro Definition Documentation

◆ BindInlet

#define BindInlet (   inlet,
  obj 
)    (inletBindings[(inlet)->type])(inlet, (ident) obj)

Binds the Inlet to obj by invoking the appropriate InletBinding function.

Definition at line 244 of file View+JSON.h.

◆ MakeInlet

#define MakeInlet (   name,
  type,
  dest,
  data 
)    (Inlet) { (name), (type), (dest), (ident) (data) }

Creates an Inlet with the specified parameters.

Definition at line 216 of file View+JSON.h.

◆ MakeInlets

#define MakeInlets (   ...)
Value:
{ \
__VA_ARGS__, \
MakeInlet(NULL, InitTypeEnd, NULL, NULL) \
}
@ InitTypeEnd
Definition View+JSON.h:41

Creates a null-termianted array of Inlets.

Definition at line 221 of file View+JSON.h.

222 { \
223 __VA_ARGS__, \
224 MakeInlet(NULL, InitTypeEnd, NULL, NULL) \
225 }

◆ MakeOutlet

#define MakeOutlet (   identifier,
  view 
)    (Outlet) { (identifier), (View **) (view) }

Creates an Outlet with the specified parameters.

Definition at line 230 of file View+JSON.h.

◆ MakeOutlets

#define MakeOutlets (   ...)
Value:
{ \
__VA_ARGS__, \
MakeOutlet(NULL, NULL) \
}

Creates a NULL-termianted array of Outlets.

Definition at line 235 of file View+JSON.h.

236 { \
237 __VA_ARGS__, \
238 MakeOutlet(NULL, NULL) \
239 }

Typedef Documentation

◆ InletBinding

typedef void(* InletBinding) (const Inlet *inlet, ident obj)

A function pointer for Inlet binding.

Parameters
inletThe Inlet.
objThe Object resolved from the JSON Dictionary.
Remarks
For Inlets of type InletTypeApplicationDefined, applications must provide a pointer to a function of this prototype as their Inlet's data. ObjectivelyMVC will invoke the function to resolve the JSON data binding.

Definition at line 186 of file View+JSON.h.

Enumeration Type Documentation

◆ InletType

enum InletType

Inlet type constants.

Enumerator
InitTypeEnd 
Remarks
Special end-of-list value for an inlet list
InletTypeBool 
Remarks
Inlet destination must be of type Bool *.
InletTypeCharacters 
Remarks
Inlet destination must be of type char **. The inbound C string is copied via strdup, and thus the receiver should free it when it is no longer needed.
InletTypeClassNames 
Remarks
Inlet destination must be of type View **.
InletTypeColor 
Remarks
Inlet destination must be of type SDL_Color *.
InletTypeDouble 
Remarks
Inlet destination must be of type double *.
InletTypeEnum 
Remarks
Inlet destination must be of an enum * type. Inlet data must provide a null- terminated array of EnumNames.
See also
valueof
MakeEnumNames
InletTypeFloat 
Remarks
Inlet destination must be of type float *.
InletTypeFont 
Remarks
Inlet destination must be of type Font **.
InletTypeImage 
Remarks
Inlet destination must be of type Image **.
InletTypeInteger 
Remarks
Inlet destination must be of type int *.
InletTypePoint 
Remarks
Inlet destination must be of type SDL_Point *.
InletTypeRectangle 
Remarks
Inlet destination must be of type SDL_Rect *.
InletTypeSize 
Remarks
Inlet destination must be of type SDL_Size *.
InletTypeStyle 
Remarks
Inlet destination must be of type View **. The Style of the specified View is populated with the attributes of the bound Dictionary.
InletTypeSubviews 
Remarks
Inlet destination must be of type View **. The subviews of the specified View are populated from the bound Array of View definitions.
InletTypeView 
Remarks
Inlet destination must be of type View **.
By default, the destination View is awoken with the inbound View definition. There are two notable exceptions to this behavior:
  • "class" - If the inbound View definition includes a "class" directive, a new View of the specified type is initialized, and the existing View is replaced and released. The type must be initialized in order for the class to be resolved. Use this behavior to substitute a specialized or custom View implementation.
  • "include" - If the inbound View definition specifies an "include" directive, the specified JSON file will be recursively processed. The existing View is replaced with the resulting View, and subsequently released.
See also
_initialize(Clazz *)
View::awakeWithDictionary(View *, const Dictionary *)
View::viewWithContentsOfFile(const char *path)
InletTypeApplicationDefined 
Remarks
Inlet destination is of an application-defined type. The Inlet data must provide an InletBinding function. That function is responsible for populating the Inlet destination.

Definition at line 36 of file View+JSON.h.

36 {
37
41 InitTypeEnd = -1,
42
47
53
58
63
68
76
81
86
91
96
101
106
111
117
123
140
146
147} InletType;
InletType
Inlet type constants.
Definition View+JSON.h:36
@ InletTypeSubviews
Definition View+JSON.h:122
@ InletTypeStyle
Definition View+JSON.h:116
@ InletTypeImage
Definition View+JSON.h:90
@ InletTypeDouble
Definition View+JSON.h:67
@ InletTypeEnum
Definition View+JSON.h:75
@ InletTypePoint
Definition View+JSON.h:100
@ InletTypeCharacters
Definition View+JSON.h:52
@ InletTypeBool
Definition View+JSON.h:46
@ InletTypeClassNames
Definition View+JSON.h:57
@ InletTypeFont
Definition View+JSON.h:85
@ InletTypeInteger
Definition View+JSON.h:95
@ InletTypeApplicationDefined
Definition View+JSON.h:145
@ InletTypeColor
Definition View+JSON.h:62
@ InletTypeView
Definition View+JSON.h:139
@ InletTypeSize
Definition View+JSON.h:110
@ InletTypeFloat
Definition View+JSON.h:80
@ InletTypeRectangle
Definition View+JSON.h:105

Function Documentation

◆ bindInlets()

OBJECTIVELYMVC_EXPORT bool bindInlets ( const Inlet inlets,
const Dictionary *  dictionary 
)

Binds each Inlet specified in inlets to the data provided in dictionary.

Parameters
inletsThe Inlets to bind.
dictionaryThe Dictionary from which to bind.
Returns
True if one or more Inlets were bound, false otherwise.

Definition at line 327 of file View+JSON.c.

327 {
328
329 assert(inlets);
330 assert(dictionary);
331
332 bool didBindInlets = false;
333
334 for (const Inlet *inlet = inlets; inlet->name; inlet++) {
335 const ident obj = $(dictionary, objectForKeyPath, inlet->name);
336 if (obj) {
337 BindInlet(inlet, obj);
338 didBindInlets = true;
339 }
340 }
341
342 return didBindInlets;
343}
#define BindInlet(inlet, obj)
Binds the Inlet to obj by invoking the appropriate InletBinding function.
Definition View+JSON.h:244
Inlets enable inbound data binding of View attributes through JSON.
Definition View+JSON.h:155
const char * name
The Inlet name, e.g. "alignment".
Definition View+JSON.h:160

Variable Documentation

◆ inletBindings

OBJECTIVELYMVC_EXPORT const InletBinding inletBindings[]

The Array of InletBindings, indexed by InletType.

Definition at line 191 of file View+JSON.h.