Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages

Zen is a C library that provides a portable foundation for software developed by LMI Technologies. A small Zen program is shown below:

#include <kApi/kApi.h> //include all zen headers
int main()
{
kAssembly assembly = kNULL; //assembly handle
kImage image = kNULL; //image handle
kSize width = 32;
kSize height = 64;
kSize i, j;
//get an initialized reference to zen's core assembly (kApiLib)
kCheck(kApiLib_Construct(&assembly));
//construct a new image object
kCheck(kImage_Construct(&image, kTypeOf(k8u), width, height, kNULL));
//set the image pixels to a test pattern
for (i = 0; i < height; ++i)
{
//get a pointer to the first element in the current row
k8u* row = kImage_RowAt(image, i);
for (j = 0; j < width; ++j)
{
row[j] = (k8u) (i + j);
}
}
//save the image using bmp format
kCheck(kImage_Export(image, "test.bmp"));
//destroy the image object
kCheck(kObject_Destroy(image));
//destroy the kApiLib assembly
kCheck(kObject_Destroy(assembly));
return kOK;
}

Zen recognizes two fundamental kinds of data: value types (e.g. k8u) and reference types (e.g. kImage). Value types (structs, enums) are simple data structures with public fields. Reference types (classes, interfaces) are opaque data structures represented with handles and accessed using functions.

Zen implements a single-inheritance, multiple-interface class model. All Zen classes descend from kObject. In the example above, this enables the kObject_Destroy method to be used on both an image object and an assembly object.

A Zen assembly is a collection of types. A program must construct an assembly before using its services and should destroy the assembly before the program exits. In the example above, the kApiLib_Construct function is used to construct an instance of Zen's core assembly (kApiLib). Zen-based libraries can define new assemblies and the types defined in one assembly can extend the types defined in another assembly.

A variety of macros are provided as syntactic aids. In the example above, the kTypeOf macro is used to obtain run-time type information (kType), while the kCheck macro is used to test function return values.

Zen is open source, provided under the MIT license. See the Zen FAQ for information on supported platforms.

See also
  FAQ, kObject, kValue, kAssembly, kType