00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2003--2007 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 CUCON_SLINK_H 00019 #define CUCON_SLINK_H 00020 00021 #include <cucon/fwd.h> 00022 #include <cu/memory.h> 00023 #include <cu/util.h> 00024 00025 CU_BEGIN_DECLARATIONS 00026 /*!\defgroup cucon_slink_h cucon/slink.h: A singly linked list. 00027 * @{\ingroup cucon_linear_mod */ 00028 00029 struct cucon_slink 00030 { 00031 cucon_slink_t next; 00032 }; 00033 00034 /*!Prepend a node with slot size \a size in front of \a rest, and return the 00035 * result. Use \ref cucon_slink_mem to obtain a pointer to the allocated slot. 00036 */ 00037 cucon_slink_t cucon_slink_prepend_mem(cucon_slink_t rest, size_t size); 00038 00039 /*!Prepend a node in front of \a rest with a slot containing \a ptr, and return 00040 * the result. */ 00041 cucon_slink_t cucon_slink_prepend_ptr(cucon_slink_t slink, void *ptr); 00042 00043 /*!The list \a l with the head node removed. 00044 * \pre \a l is not empty (\c NULL). */ 00045 CU_SINLINE cucon_slink_t cucon_slink_next(cucon_slink_t l) { return l->next; } 00046 00047 /*!The memory slot of the head node of \a l. 00048 * \pre \a l is not empty. */ 00049 CU_SINLINE void *cucon_slink_mem(cucon_slink_t l) 00050 { return CU_ALIGNED_MARG_END(cucon_slink_t, l); } 00051 00052 /*!The value of the head node of \a l, assuming it's slot contains a pointer. 00053 * \pre \a l is not empty. */ 00054 CU_SINLINE void *cucon_slink_ptr(cucon_slink_t l) 00055 { return *(void **)cucon_slink_mem(l); } 00056 00057 /*!@}*/ 00058 00059 /*\ingroup deprecated \deprecated, just use \c NULL. */ 00060 CU_SINLINE cucon_slink_t cucon_slink_empty(void) { return NULL; } 00061 /*\ingroup deprecated \deprecated, just compare to \c NULL. */ 00062 CU_SINLINE cu_bool_t cucon_slink_is_empty(cucon_slink_t l) { return l==NULL; } 00063 /*\ingroup deprecated \deprecated Old name. */ 00064 #define cucon_slink_get_mem cucon_slink_mem 00065 /*\ingroup deprecated \deprecated Old name. */ 00066 #define cucon_slink_get_ptr cucon_slink_ptr 00067 00068 CU_END_DECLARATIONS 00069 00070 #endif