1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/*********************************************************************************************************
* Software License Agreement (BSD License) *
* Author: Sebastien Decugis <sdecugis@freediameter.net> *
* *
* Copyright (c) 2013, WIDE Project and NICT *
* All rights reserved. *
* *
* Redistribution and use of this software in source and binary forms, with or without modification, are *
* permitted provided that the following conditions are met: *
* *
* * Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other *
* materials provided with the distribution. *
* *
* * Neither the name of the WIDE Project or NICT nor the *
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission of WIDE Project and *
* NICT. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*********************************************************************************************************/
/* Do not include this directly, use dbg_interactive.i instead */
/****** LISTS *********/
%extend fd_list {
/* allow a parameter in the constructor, and perform the fd_list_init operation */
fd_list(void * o = NULL) {
struct fd_list * li;
li = (struct fd_list *) malloc(sizeof(struct fd_list));
if (!li) {
DI_ERROR_MALLOC;
return NULL;
}
fd_list_init(li, o);
return li;
}
/* Unlink before freeing */
~fd_list() {
fd_list_unlink($self);
free($self);
}
/* For debug, show the values of the list */
void dump() {
fd_log_debug("list: %p", $self);
fd_log_debug(" - next: %p", $self->next);
fd_log_debug(" - prev: %p", $self->prev);
fd_log_debug(" - head: %p", $self->head);
fd_log_debug(" - o : %p", $self->o);
}
/* Insert before/after wrapper */
void insert_prev(struct fd_list * li) {
fd_list_insert_before($self, li);
}
void insert_next(struct fd_list * li) {
fd_list_insert_after($self, li);
}
/* Test for emptyness */
PyObject * isempty() {
PyObject * ret;
if (FD_IS_LIST_EMPTY($self))
ret = Py_True;
else
ret = Py_False;
Py_XINCREF(ret);
return ret;
}
/* Concatenate two lists */
void concat(struct fd_list * li) {
fd_list_move_end($self, li);
}
/* Unlink without freeing */
void detach() {
fd_list_unlink($self);
}
/* Return the list as python list of elements */
PyObject * enum_as(char * type = NULL, int dont_use_o = 0) {
struct fd_list *li;
swig_type_info * desttype = NULL;
PyObject * rl;
if ($self->head != $self) {
DI_ERROR(EINVAL, NULL, "This method can only be called on the list sentinel.");
return NULL;
}
if (type) {
desttype = SWIG_TypeQuery(type);
if (!desttype) {
DI_ERROR(EINVAL, NULL, "Unable to resolve this type. Please check the form: 'struct blahbla *'");
return NULL;
}
}
if (desttype == NULL) {
/* fallback to fd_list */
desttype = SWIGTYPE_p_fd_list;
/* in this case, don't follow the 'o' link */
dont_use_o = 1;
}
rl = PyList_New(0);
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
for (li = $self->next; li != $self; li = li->next) {
void * obj = NULL;
if (dont_use_o || li->o == NULL)
obj = li;
else
obj = li->o;
PyList_Append(rl, SWIG_NewPointerObj(obj, desttype, 0 ));
}
Py_XINCREF(rl);
SWIG_PYTHON_THREAD_END_BLOCK;
return rl;
}
};
|