Closed SanderMertens closed 6 years ago
With this function implemented, some other less often used functions can be deprecated to reduce the size of the API. Functions that could be deprecated are:
corto_declareOrphan
corto_createOrphan
corto_findOrDeclare
corto_findOrCreate
corto_find
corto_fromcontent
corto_object_fromcontent
This function has been changed in the v2.0 API upgrade, so that it becomes more readable, and more arguments can be added in the future without breaking backwards compatibility. An example:
corto_object foo = corto(CORTO_DECLARE, {.parent = root_o, .id = "foo"});
To enable this syntax, the function accepts an argument of a struct-type that contains all the possible arguments of the function. This enables arguments to be referenced by name. The function itself is now a macro which includes a cast to the corto_action
type for the second parameter, so that the fully expanded function call looks like this:
corto_object foo = corto(CORTO_DECLARE, (corto_action){.parent = root_o, .id = "foo"});
In some cases the regular store API (
corto_declareChild
,corto_define
etc) is not flexible enough, or performs actions that in some contexts are redundant. To enable applications to do more powerful things with the store, and optimize certain scenarios, a lower-level API call is needed.Examples of redundancy are:
corto_declareChild
API always checks if the identifier is recursive (foo/bar
) which adds performance overhead. In a lot of cases, this check is not needed.fromcontent
functions all accept a string identifier for the content type which has to be looked up. It would be nice if a function could use a cached contentType handle directly.Additionally, the sequence of default store operations can become quite complex in multi-threaded scenarios where multiple threads can be instantiating the same object at the same time, values have to be assigned, and objects have to be either looked up or created.
The current standard API is already a thin layer upon a smaller, more powerful (but also more complex) API. A new function should be added that wraps around the internal APIs, and allows for executing multiple low-level operations in the correct sequence.
The API could look like this:
For example, an application that needs to either find or create an object in a multithreaded context, and define an object when its created, and update an object when its found, could be implemented with a single function call:
Because the interface is quite complex, the API should initially be marked as experimental to allow for improvements that are backwards incompatible