1 /* 2 * Python object definition of the sequence and iterator object of keys 3 * 4 * Copyright (C) 2013-2021, Joachim Metz <joachim.metz@gmail.com> 5 * 6 * Refer to AUTHORS for acknowledgements. 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #if !defined( _PYCREG_KEYS_H ) 23 #define _PYCREG_KEYS_H 24 25 #include <common.h> 26 #include <types.h> 27 28 #include "pycreg_libcreg.h" 29 #include "pycreg_python.h" 30 31 #if defined( __cplusplus ) 32 extern "C" { 33 #endif 34 35 typedef struct pycreg_keys pycreg_keys_t; 36 37 struct pycreg_keys 38 { 39 /* Python object initialization 40 */ 41 PyObject_HEAD 42 43 /* The parent object 44 */ 45 PyObject *parent_object; 46 47 /* The get item by index callback function 48 */ 49 PyObject* (*get_item_by_index)( 50 PyObject *parent_object, 51 int index ); 52 53 /* The current index 54 */ 55 int current_index; 56 57 /* The number of items 58 */ 59 int number_of_items; 60 }; 61 62 extern PyTypeObject pycreg_keys_type_object; 63 64 PyObject *pycreg_keys_new( 65 PyObject *parent_object, 66 PyObject* (*get_item_by_index)( 67 PyObject *parent_object, 68 int index ), 69 int number_of_items ); 70 71 int pycreg_keys_init( 72 pycreg_keys_t *sequence_object ); 73 74 void pycreg_keys_free( 75 pycreg_keys_t *sequence_object ); 76 77 Py_ssize_t pycreg_keys_len( 78 pycreg_keys_t *sequence_object ); 79 80 PyObject *pycreg_keys_getitem( 81 pycreg_keys_t *sequence_object, 82 Py_ssize_t item_index ); 83 84 PyObject *pycreg_keys_iter( 85 pycreg_keys_t *sequence_object ); 86 87 PyObject *pycreg_keys_iternext( 88 pycreg_keys_t *sequence_object ); 89 90 #if defined( __cplusplus ) 91 } 92 #endif 93 94 #endif /* !defined( _PYCREG_KEYS_H ) */ 95 96