00001 /* Copyright 2005-2006 Garrett Rooney. 00002 * 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 */ 00015 00016 /** 00017 * @file etl_variables.h 00018 * @brief Functions and data structures for working with ETL variables 00019 */ 00020 00021 #ifndef ETL_VARIABLES_H 00022 #define ETL_VARIABLES_H 00023 00024 #include <apr.h> 00025 #include <apr_hash.h> 00026 #include <apr_tables.h> 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif /* __cplusplus */ 00031 00032 /** The types of variables that can appear in a template. */ 00033 typedef enum { 00034 ETL_VARIABLE_STRING, /**< @c char * */ 00035 ETL_VARIABLE_INTEGER, /**< @c apr_int64_t */ 00036 ETL_VARIABLE_ARRAY, /**< @c apr_array_header_t of @c etl_variable_t's */ 00037 ETL_VARIABLE_HASH /**< @c apr_hash_t of <tt>char *</tt> to variable */ 00038 } etl_variable_type_t; 00039 00040 /** A variable that can be accessed inside a template. */ 00041 typedef struct { 00042 etl_variable_type_t type; 00043 00044 union { 00045 char *s; 00046 apr_int64_t i; 00047 apr_array_header_t *a; 00048 apr_hash_t *h; 00049 } contents; 00050 } etl_variable_t; 00051 00052 /* note: the following helper functions are TOTALLY OPTIONAL, in fact there 00053 * are situations (usually with the int and string versions) where you 00054 * DON'T want to use them because they result in excess copying, but 00055 * i find myself writing them over and over again, so here they are. */ 00056 00057 /** 00058 * Helper function to turn an @c apr_int64_t into a template variable, 00059 * the variable is allocated in @a pool. 00060 */ 00061 etl_variable_t * 00062 etl_variable_make_int(apr_int64_t i, apr_pool_t *pool); 00063 00064 /** 00065 * Helper function to turn a string @a str into a template variable, 00066 * the variable is allocated in @a pool. */ 00067 etl_variable_t * 00068 etl_variable_make_str(const char *str, apr_pool_t *pool); 00069 00070 /** 00071 * Helper function to create a template variable wrapped around an 00072 * empty array. The array is initially sized to hold @a nitems and 00073 * is allocated in @a pool. 00074 */ 00075 etl_variable_t * 00076 etl_variable_make_array(int nitems, apr_pool_t *pool); 00077 00078 /** 00079 * Helper function to create a template variable wrapped around an 00080 * empty hash. The array is allocated in @a pool. 00081 */ 00082 etl_variable_t * 00083 etl_variable_make_hash(apr_pool_t *pool); 00084 00085 #ifdef __cplusplus 00086 } 00087 #endif /* __cplusplus */ 00088 00089 #endif /* ETL_VARIABLES_H */
1.4.4