Skip to content

izuzanak/cont

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cont - container generator

Build Status CI

C/C++ code preprocessor generating code of containers. Generated code is based on marks found in processed code.

Following container types are supported:

  • struct - Simple structure composed from contained elements.
  • array - Array of contained elements.
  • queue - One direction queue of contained elements.
  • list - List of contained elements.
  • rb_tree - Red-black tree of contained elements.

Motivation for container generator

Every container is based on continuous memory block

Data of contained elements are stored in continuous block of memory. Memory block is resized when its size is not sufficient for requested count of elements. Copying of memory block while resizing is performed by realloc, no knowledge of objects structure other than its size is required.

Persistent unsigned indexes instead of iterators

Elements inside containers are identified by indexes (unsigned int) which are persistent and cannot be invalidated by any operation other than removal of this particular element. This allows usage of element indexes as members in other structures related to container, rather than pointers.

Constructor/destructor not used at all

C++ Constructors and destructors are not used by generated structures. Methods init and clear are instead used for object initialization and clear.

init - After creation of object (allocation on heap, or on stack) it must be initialized by method init or related metods (init_size).

clear - Clears object content, release allocated resources and reset object state to initialized state. Object is not invalidated by clear method.

Generated code is human readable and accessible

Containers code is generated to .cc file. Generated code can be read, modified, or copied and used in another projects.

Build container generator

Enter build directory build.

cd build

Process cmake source.

cmake ..

Build container generator.

make -j$(nproc)

Examples

Examples of container generator usage are presented in directory: cont/examples.