/* Copyright 2005-2006 Garrett Rooney. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file etl_variables.h * @brief Functions and data structures for working with ETL variables */ #ifndef ETL_VARIABLES_H #define ETL_VARIABLES_H #include #include #include #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** The types of variables that can appear in a template. */ typedef enum { ETL_VARIABLE_STRING, /**< @c char * */ ETL_VARIABLE_INTEGER, /**< @c apr_int64_t */ ETL_VARIABLE_ARRAY, /**< @c apr_array_header_t of @c etl_variable_t's */ ETL_VARIABLE_HASH /**< @c apr_hash_t of char * to variable */ } etl_variable_type_t; /** A variable that can be accessed inside a template. */ typedef struct { etl_variable_type_t type; union { char *s; apr_int64_t i; apr_array_header_t *a; apr_hash_t *h; } contents; } etl_variable_t; /* note: the following helper functions are TOTALLY OPTIONAL, in fact there * are situations (usually with the int and string versions) where you * DON'T want to use them because they result in excess copying, but * i find myself writing them over and over again, so here they are. */ /** * Helper function to turn an @c apr_int64_t into a template variable, * the variable is allocated in @a pool. */ etl_variable_t * etl_variable_make_int(apr_int64_t i, apr_pool_t *pool); /** * Helper function to turn a string @a str into a template variable, * the variable is allocated in @a pool. */ etl_variable_t * etl_variable_make_str(const char *str, apr_pool_t *pool); /** * Helper function to create a template variable wrapped around an * empty array. The array is initially sized to hold @a nitems and * is allocated in @a pool. */ etl_variable_t * etl_variable_make_array(int nitems, apr_pool_t *pool); /** * Helper function to create a template variable wrapped around an * empty hash. The array is allocated in @a pool. */ etl_variable_t * etl_variable_make_hash(apr_pool_t *pool); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* ETL_VARIABLES_H */