61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
#ifndef LTM_TEMPLATE
|
|
#define LTM_TEMPLATE
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "ltm/common.h"
|
|
|
|
/**
|
|
* Represents a compiled template
|
|
*/
|
|
typedef struct ltm_template ltm_template;
|
|
|
|
/**
|
|
* Compile the given template.
|
|
*
|
|
* @param out where to store pointer to newly allocated `ltm_template`
|
|
* @param template nul-terminated string containing the template
|
|
*/
|
|
ltm_err ltm_template_compile(ltm_template **out, const char *template);
|
|
|
|
/**
|
|
* Compile the given template with a given length.
|
|
*
|
|
* @param out where to store pointer to newly allocated `ltm_template`
|
|
* @param template char buffer containing the template
|
|
* @param len length of the char buffer
|
|
*/
|
|
ltm_err ltm_template_compile_n(ltm_template **out, const char *template,
|
|
size_t len);
|
|
|
|
/**
|
|
* Represents a specific instance of a template.
|
|
*/
|
|
typedef struct ltm_instance ltm_instance;
|
|
|
|
/**
|
|
* Create a new instance of the given template.
|
|
*/
|
|
ltm_err ltm_template_instantiate(ltm_instance **out,
|
|
const ltm_template *template);
|
|
|
|
typedef enum ltm_instance_block_type {
|
|
ltm_instance_block_type_buf = 0,
|
|
} ltm_instance_block_type;
|
|
|
|
/**
|
|
* Add a new variable to the template.
|
|
*/
|
|
ltm_err ltm_instance_block_add_var(ltm_instance *instance, const char *name,
|
|
ltm_instance_block_type type, void *data,
|
|
size_t len);
|
|
|
|
/**
|
|
* Add a new nested instance to the instance, returning a handle to the nested
|
|
* instance.
|
|
*/
|
|
ltm_err ltm_instance_block_add_nested(ltm_instance **out,
|
|
ltm_instance *instance, const char *name);
|
|
|
|
#endif
|