Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 1 | :: # Copyright 2014, Big Switch Networks, Inc. |
| 2 | :: # |
| 3 | :: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with |
| 4 | :: # the following special exception: |
| 5 | :: # |
| 6 | :: # LOXI Exception |
| 7 | :: # |
| 8 | :: # As a special exception to the terms of the EPL, you may distribute libraries |
| 9 | :: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided |
| 10 | :: # that copyright and licensing notices generated by LoxiGen are not altered or removed |
| 11 | :: # from the LoxiGen Libraries and the notice provided below is (i) included in |
| 12 | :: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any |
| 13 | :: # documentation for the LoxiGen Libraries, if distributed in binary form. |
| 14 | :: # |
| 15 | :: # Notice: "Copyright 2014, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler." |
| 16 | :: # |
| 17 | :: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain |
| 18 | :: # a copy of the EPL at: |
| 19 | :: # |
| 20 | :: # http://www.eclipse.org/legal/epl-v10.html |
| 21 | :: # |
| 22 | :: # Unless required by applicable law or agreed to in writing, software |
| 23 | :: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | :: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 25 | :: # EPL for the specific language governing permissions and limitations |
| 26 | :: # under the EPL. |
| 27 | :: |
| 28 | :: include('_copyright.c') |
| 29 | :: include('_pragmas.c') |
| 30 | |
| 31 | #include "loci_log.h" |
| 32 | #include "loci_int.h" |
| 33 | |
| 34 | /** |
| 35 | * Associate an iterator with a list |
| 36 | * @param list The list to iterate over |
| 37 | * @param obj The list entry iteration pointer |
| 38 | * @return OF_ERROR_RANGE if the list is empty (end of list) |
| 39 | * |
| 40 | * The obj instance is completely initialized. The caller is responsible |
| 41 | * for cleaning up any wire buffers associated with obj before this call |
| 42 | */ |
| 43 | |
| 44 | int |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 45 | ${cls}_first(${cls}_t *list, of_list_iter_t iter) |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 46 | { |
| 47 | int rv; |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 48 | of_object_t *obj = iter.obj; |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 49 | |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 50 | ${e_cls}_init(obj, list->version, -1, 1); |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 51 | |
| 52 | if ((rv = of_list_first(list, obj)) < 0) { |
| 53 | return rv; |
| 54 | } |
| 55 | |
Rich Lane | 83f958d | 2014-06-13 15:01:40 -0700 | [diff] [blame] | 56 | :: if e_uclass.virtual: |
| 57 | ${e_cls}_wire_object_id_get(obj, &obj->object_id); |
| 58 | :: #endif |
| 59 | |
Rich Lane | bbf5e1d | 2014-06-13 15:34:21 -0700 | [diff] [blame] | 60 | :: if wire_length_get != 'NULL': |
| 61 | ${wire_length_get}(obj, &obj->length); |
Rich Lane | 83f958d | 2014-06-13 15:01:40 -0700 | [diff] [blame] | 62 | :: #endif |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 63 | |
| 64 | return rv; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Advance an iterator to the next element in a list |
| 69 | * @param list The list being iterated |
| 70 | * @param obj The list entry iteration pointer |
| 71 | * @return OF_ERROR_RANGE if already at the last entry on the list |
| 72 | * |
| 73 | */ |
| 74 | |
| 75 | int |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 76 | ${cls}_next(${cls}_t *list, of_list_iter_t iter) |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 77 | { |
| 78 | int rv; |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 79 | of_object_t *obj = iter.obj; |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 80 | |
| 81 | if ((rv = of_list_next(list, obj)) < 0) { |
| 82 | return rv; |
| 83 | } |
| 84 | |
Rich Lane | 83f958d | 2014-06-13 15:01:40 -0700 | [diff] [blame] | 85 | :: if e_uclass.virtual: |
| 86 | ${e_cls}_wire_object_id_get(obj, &obj->object_id); |
| 87 | :: #endif |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 88 | |
Rich Lane | bbf5e1d | 2014-06-13 15:34:21 -0700 | [diff] [blame] | 89 | :: if wire_length_get != 'NULL': |
| 90 | ${wire_length_get}(obj, &obj->length); |
Rich Lane | 83f958d | 2014-06-13 15:01:40 -0700 | [diff] [blame] | 91 | :: #endif |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 92 | |
| 93 | return rv; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Set up to append an object of type ${e_cls} to an ${cls}. |
| 98 | * @param list The list that is prepared for append |
| 99 | * @param obj Pointer to object to hold data to append |
| 100 | * |
| 101 | * The obj instance is completely initialized. The caller is responsible |
| 102 | * for cleaning up any wire buffers associated with obj before this call. |
| 103 | * |
| 104 | * See the generic documentation for of_list_append_bind. |
| 105 | */ |
| 106 | |
| 107 | int |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 108 | ${cls}_append_bind(${cls}_t *list, of_list_iter_t iter) |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 109 | { |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 110 | return of_list_append_bind(list, iter.obj); |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Append an object to a ${cls} list. |
| 115 | * |
| 116 | * This copies data from obj and leaves item untouched. |
| 117 | * |
| 118 | * See the generic documentation for of_list_append. |
| 119 | */ |
| 120 | |
| 121 | int |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 122 | ${cls}_append(${cls}_t *list, of_list_iter_t iter) |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 123 | { |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 124 | return of_list_append(list, iter.obj); |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 125 | } |