00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2005--2009 Petter Urkedal <urkedal@nbi.dk> 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef CU_IDR_H 00019 #define CU_IDR_H 00020 00021 #include <cuoo/type.h> 00022 #include <cu/wchar.h> 00023 00024 CU_BEGIN_DECLARATIONS 00025 /*!\defgroup cu_idr_h cu/idr.h: Identifiers (Strings with Pointer Equality) 00026 * @{ \ingroup cu_type_mod */ 00027 00028 struct cu_idr 00029 { 00030 CUOO_HCOBJ 00031 cu_word_t key_size; 00032 }; 00033 00034 extern cuoo_type_t cuP_idr_type; 00035 00036 /*!Returns the type descriptor of all \c cu_idr_t objects. */ 00037 CU_SINLINE cuoo_type_t cu_idr_type() 00038 { return cuP_idr_type; } 00039 00040 /*!True iff the dynamically typed object at \a dyn is an \c cu_idr_t. */ 00041 CU_SINLINE cu_bool_t cu_is_idr(void *dyn) 00042 { return cuex_meta(dyn) == cuoo_type_to_meta(cu_idr_type()); } 00043 00044 /*!Returns the identifier with the name \a cstr. The result is hashconsed, 00045 * meaning that two simultaneously live \c cu_idr_t objects constructed 00046 * from the same string (according to strcmp) have identical pointers. */ 00047 cu_idr_t cu_idr_by_cstr(char const *cstr); 00048 00049 /*!Returns the identifier with the name given by \a arr to \a arr + 00050 * \a size. See \ref cu_idr_by_cstr. */ 00051 cu_idr_t cu_idr_by_charr(char const *arr, size_t size); 00052 00053 /*!Returns the identifier with the name given by \a arr to \a arr + \a len. 00054 * The Unicode string is converted to UTF-8. */ 00055 cu_idr_t cu_idr_by_wchararr(cu_wchar_t const *arr, size_t len); 00056 00057 /*!Returns the identifier of name \a s. The Unicode string is converted to 00058 * UTF-8. */ 00059 cu_idr_t cu_idr_by_wstring(cu_wstring_t s); 00060 00061 /*!Return a C string strcmp-equal to the one passed upon costruction. */ 00062 CU_SINLINE char const *cu_idr_to_cstr(cu_idr_t idr) 00063 { return (char const *)(idr + 1); } 00064 00065 /*!A simple pointer comparison. */ 00066 CU_SINLINE cu_bool_t cu_idr_eq(cu_idr_t idr0, cu_idr_t idr1) 00067 { return idr0 == idr1; } 00068 00069 /*!Returns <tt>strcmp(cu_idr_to_cstr(\a idr0), cu_idr_to_cstr(\a idr1))</tt>.*/ 00070 int cu_idr_strcmp(cu_idr_t idr0, cu_idr_t idr1); 00071 00072 #define cu_idr_of_cstrq cu_idr_of_cstr 00073 #define cu_idr_to_cstrq cu_idr_to_cstr 00074 00075 #ifndef CU_IN_DOXYGEN 00076 extern cu_clop(cu_idr_strcmp_clop, int, cu_idr_t, cu_idr_t); 00077 #endif 00078 00079 /*!@}*/ 00080 CU_END_DECLARATIONS 00081 00082 #endif