Main Page | Data Structures | Directories | File List | Data Fields | Globals

lcn_types.h

Go to the documentation of this file.
00001 /* Copyright 2005 The Apache Software Foundation or its licensors, as
00002  * applicable.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /**
00018  * @file lcn_types.h
00019  * @brief Random stuff that doesn't fit anywhere else
00020  */
00021 
00022 #ifndef _LCN_TYPES_H
00023 #define _LCN_TYPES_H
00024 
00025 #include <apr.h>
00026 #include <apr_pools.h>
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif /* __cplusplus */
00031 
00032 /** Since we use C89 we need a boolean type... */
00033 typedef int lcn_boolean_t;
00034 
00035 #ifndef FALSE
00036 /** You figure it out. */
00037 #define FALSE 0
00038 #endif
00039 
00040 #ifndef TRUE
00041 /** You figure it out. */
00042 #define TRUE 1
00043 #endif
00044 
00045 /** Our exception object. */
00046 typedef struct lcn_error_t {
00047   apr_status_t apr_err;      /**< The underlying APR error */
00048 
00049   const char *message;       /**< Human readable error message */
00050 
00051   struct lcn_error_t *child; /**< The next error in the chain, or @c NULL */
00052 
00053   apr_pool_t *pool;          /**< The pool this error was allocated in */
00054 
00055 } lcn_error_t;
00056 
00057 /** The best kind of error. */
00058 #define LCN_NO_ERROR 0
00059 
00060 /** Create a new error with underlying error code @a apr_err, wrapping around
00061  * @a child, with error message @a message.
00062  */
00063 lcn_error_t *
00064 lcn_error_create (apr_status_t apr_err,
00065                   lcn_error_t *child,
00066                   const char *message);
00067 
00068 /** A @c printf style version of @c lcn_error_create. */
00069 lcn_error_t *
00070 lcn_error_createf (apr_status_t apr_err,
00071                    lcn_error_t *child,
00072                    const char *fmt,
00073                    ...)
00074 #ifdef DOXYGEN_SHOULD_SKIP_THIS
00075                    ;
00076 #else
00077                    __attribute__ ((format (printf, 3, 4)));
00078 #endif
00079 
00080 /** Destroy @a error. */
00081 void lcn_error_clear (lcn_error_t *error);
00082 
00083 /** A handy wrapper for functions that return an @c lcn_error_t, just returns
00084  * the error to our caller if it's not @c LCN_NO_ERROR.
00085  */
00086 #define LCN_ERR(expr)                    \
00087   do {                                   \
00088     lcn_error_t *lcn_err__temp = (expr); \
00089     if (lcn_err__temp)                   \
00090       return lcn_err__temp;              \
00091     } while (0)
00092 
00093 /** A java style 16 bit char. */
00094 typedef apr_uint16_t lcn_char_t;
00095 
00096 /** Count the number of characters in a string of lcn_char_t's */
00097 apr_size_t lcn_strlen (const lcn_char_t *str);
00098 
00099 /** Get the size of a string of lcn_char_t's in bytes */
00100 #define LCN_STRING_SIZE(str) ((lcn_strlen (str) + 1) * sizeof (lcn_char_t))
00101 
00102 /** Lexographically compare @a first and @a second. */
00103 int lcn_strcmp (const lcn_char_t *first, const lcn_char_t *second);
00104 
00105 /** Return a copy of @a str, allocated in @a pool. */
00106 lcn_char_t *
00107 lcn_strcpy (const lcn_char_t *str, apr_pool_t *pool);
00108 
00109 /** Convert @a in into a cstring @a out, allocated in @a pool.
00110  *
00111  * This will result in an error if @a in cannot be represented in ASCII
00112  * characters.
00113  */
00114 lcn_error_t *
00115 lcn_str_to_cstring (char **out, const lcn_char_t *in, apr_pool_t *pool);
00116 
00117 /** Create a string of @c lcn_char_ts that corresponds to the contents of 
00118  * @a in, allocated in @a pool.
00119  */
00120 lcn_char_t *
00121 lcn_str_from_cstring (const char *in, apr_pool_t *pool);
00122 
00123 /** Index into an apr_array_header_t */
00124 #define APR_ARRAY_IDX(ary,i,type) (((type *)(ary)->elts)[i])
00125 
00126 /** Easier array-pushing syntax */
00127 #define APR_ARRAY_PUSH(ary,type) (*((type *)apr_array_push (ary)))
00128 
00129 /** A convenience wrapper for @c apr_pool_create. */
00130 apr_pool_t *lcn_pool_create (apr_pool_t *parent);
00131 
00132 /** For symmetry with @c lcn_pool_create. */
00133 #define lcn_pool_destroy apr_pool_destroy
00134 
00135 #ifdef __cplusplus
00136 }
00137 #endif /* __cplusplus */
00138 
00139 #endif

Generated on Sat Mar 26 08:12:11 2005 for Lucene4c by  doxygen 1.4.0