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 ,
  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 238 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 210 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 215 of file View+JSON.h.

216 { \
217 __VA_ARGS__, \
218 MakeInlet(NULL, InitTypeEnd, NULL, NULL) \
219 }

◆ MakeOutlet

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

Creates an Outlet with the specified parameters.

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

◆ MakeOutlets

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

Creates a NULL-termianted array of Outlets.

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

230 { \
231 __VA_ARGS__, \
232 MakeOutlet(NULL, NULL) \
233 }

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 180 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 *.
InletTypeInteger 
Remarks
Inlet destination must be of type Image **.
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
90
95
100
105
111
117
134
140
141} InletType;
InletType
Inlet type constants.
Definition View+JSON.h:36
@ InletTypeSubviews
Definition View+JSON.h:116
@ InletTypeStyle
Definition View+JSON.h:110
@ InletTypeDouble
Definition View+JSON.h:67
@ InletTypeEnum
Definition View+JSON.h:75
@ InletTypePoint
Definition View+JSON.h:94
@ InletTypeCharacters
Definition View+JSON.h:52
@ InletTypeBool
Definition View+JSON.h:46
@ InletTypeClassNames
Definition View+JSON.h:57
@ InletTypeInteger
Definition View+JSON.h:89
@ InletTypeApplicationDefined
Definition View+JSON.h:139
@ InletTypeColor
Definition View+JSON.h:62
@ InletTypeView
Definition View+JSON.h:133
@ InletTypeSize
Definition View+JSON.h:104
@ InletTypeFloat
Definition View+JSON.h:80
@ InletTypeRectangle
Definition View+JSON.h:99

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 303 of file View+JSON.c.

303 {
304
305 assert(inlets);
306 assert(dictionary);
307
308 bool didBindInlets = false;
309
310 for (const Inlet *inlet = inlets; inlet->name; inlet++) {
311 const ident obj = $(dictionary, objectForKeyPath, inlet->name);
312 if (obj) {
313 BindInlet(inlet, obj);
314 didBindInlets = true;
315 }
316 }
317
318 return didBindInlets;
319}
#define BindInlet(inlet, obj)
Binds the Inlet to obj by invoking the appropriate InletBinding function.
Definition View+JSON.h:238
Inlets enable inbound data binding of View attributes through JSON.
Definition View+JSON.h:149
const char * name
The Inlet name, e.g. "alignment".
Definition View+JSON.h:154

Variable Documentation

◆ inletBindings

OBJECTIVELYMVC_EXPORT const InletBinding inletBindings[]

The Array of InletBindings, indexed by InletType.

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