Apache Portable Runtime
apr_optional.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  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 #ifndef APR_OPTIONAL_H
00018 #define APR_OPTIONAL_H
00019 
00020 #include "apu.h"
00021 /** 
00022  * @file apr_optional.h
00023  * @brief APR-UTIL registration of functions exported by modules
00024  */
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 /** 
00030  * @defgroup APR_Util_Opt Optional Functions
00031  * @ingroup APR
00032  *
00033  * Typesafe registration and retrieval of functions that may not be present
00034  * (i.e. functions exported by optional modules)
00035  * @{
00036  */
00037 
00038 /**
00039  * The type of an optional function.
00040  * @param name The name of the function
00041  */
00042 #define APR_OPTIONAL_FN_TYPE(name) apr_OFN_##name##_t
00043 
00044 /**
00045  * Declare an optional function.
00046  * @param ret The return type of the function
00047  * @param name The name of the function
00048  * @param args The function arguments (including brackets)
00049  */
00050 #define APR_DECLARE_OPTIONAL_FN(ret,name,args) \
00051 typedef ret (APR_OPTIONAL_FN_TYPE(name)) args
00052 
00053 /**
00054  * XXX: This doesn't belong here, then!
00055  * Private function! DO NOT USE! 
00056  * @internal
00057  */
00058 
00059 typedef void (apr_opt_fn_t)(void);
00060 /** @internal */
00061 APR_DECLARE_NONSTD(void) apr_dynamic_fn_register(const char *szName, 
00062                                                   apr_opt_fn_t *pfn);
00063 
00064 /**
00065  * Register an optional function. This can be later retrieved, type-safely, by
00066  * name. Like all global functions, the name must be unique. Note that,
00067  * confusingly but correctly, the function itself can be static!
00068  * @param name The name of the function
00069  */
00070 #define APR_REGISTER_OPTIONAL_FN(name) do { \
00071   APR_OPTIONAL_FN_TYPE(name) *apu__opt = name; \
00072   apr_dynamic_fn_register(#name,(apr_opt_fn_t *)apu__opt); \
00073 } while (0)
00074 
00075 /** @internal
00076  * Private function! DO NOT USE! 
00077  */
00078 APR_DECLARE(apr_opt_fn_t *) apr_dynamic_fn_retrieve(const char *szName);
00079 
00080 /**
00081  * Retrieve an optional function. Returns NULL if the function is not present.
00082  * @param name The name of the function
00083  */
00084 #define APR_RETRIEVE_OPTIONAL_FN(name) \
00085         (APR_OPTIONAL_FN_TYPE(name) *)apr_dynamic_fn_retrieve(#name)
00086 
00087 /** @} */
00088 #ifdef __cplusplus
00089 }
00090 #endif
00091 
00092 #endif /* APR_OPTIONAL_H */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines