00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2006--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 CUCON_FRAME_H 00019 #define CUCON_FRAME_H 00020 00021 #include <cucon/fwd.h> 00022 00023 CU_BEGIN_DECLARATIONS 00024 /** \defgroup cucon_frame_h cucon/frame.h: Constructive Stack 00025 ** @{ \ingroup cucon_linear_mod 00026 ** 00027 ** This implements a stack with constructive operations. The time and space 00028 ** complexity are logarithmic in the number of stack levels. 00029 ** 00030 ** \see cucon_stack_h 00031 **/ 00032 00033 #ifndef CU_IN_DOXYGEN 00034 00035 CU_SINLINE void ** 00036 cuconP_frame_link_slot(void *frame, cu_logsize_fast_t i) 00037 { 00038 return (void **)((char *)frame 00039 - sizeof(uintptr_t) 00040 - (i + 1)*sizeof(void *)); 00041 } 00042 00043 CU_SINLINE uintptr_t * 00044 cuconP_frame_depth_slot(void *frame) 00045 { return ((uintptr_t *)frame - 1); } 00046 00047 #endif 00048 00049 /** The depth of \a frame, where \c NULL has depth 0. */ 00050 CU_SINLINE size_t cucon_frame_depth(void *frame) 00051 { return frame? *cuconP_frame_depth_slot(frame) : 0; } 00052 00053 /** Push a subframe of \a frame with \a size bytes of data. Pass \a frame = \c 00054 ** NULL to create a top level frame. The returned pointer points into the 00055 ** allocated memory where the user data starts. */ 00056 void *cucon_frame_push(void *frame, size_t size); 00057 00058 /** The parent frame of \a frame, where \a frame is a pointer which was 00059 ** obtained with \ref cucon_frame_push. */ 00060 CU_SINLINE void *cucon_frame_pop(void *frame) 00061 { return *cuconP_frame_link_slot(frame, 0); } 00062 00063 /** Equivalent to the composition of \a depth calls to \ref cucon_frame_pop, 00064 ** except that the time complexity is logarithmic in \a depth. */ 00065 void *cucon_frame_at(void *frame, size_t depth); 00066 00067 /** @} */ 00068 CU_END_DECLARATIONS 00069 00070 #endif