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 | 3094326 | 2014-11-07 09:04:13 -0800 | [diff] [blame] | 45 | ${cls}_first(${cls}_t *list, of_object_t *obj) |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 46 | { |
| 47 | int rv; |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 48 | |
Rich Lane | 7fdaa5c | 2014-10-27 18:14:59 -0700 | [diff] [blame] | 49 | ${e_cls}_init(obj, list->version, -1, 1); |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 50 | |
| 51 | if ((rv = of_list_first(list, obj)) < 0) { |
| 52 | return rv; |
| 53 | } |
| 54 | |
Rich Lane | 83f958d | 2014-06-13 15:01:40 -0700 | [diff] [blame] | 55 | :: if e_uclass.virtual: |
| 56 | ${e_cls}_wire_object_id_get(obj, &obj->object_id); |
| 57 | :: #endif |
| 58 | |
Rich Lane | bbf5e1d | 2014-06-13 15:34:21 -0700 | [diff] [blame] | 59 | :: if wire_length_get != 'NULL': |
| 60 | ${wire_length_get}(obj, &obj->length); |
Rich Lane | 83f958d | 2014-06-13 15:01:40 -0700 | [diff] [blame] | 61 | :: #endif |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 62 | |
| 63 | return rv; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Advance an iterator to the next element in a list |
| 68 | * @param list The list being iterated |
| 69 | * @param obj The list entry iteration pointer |
| 70 | * @return OF_ERROR_RANGE if already at the last entry on the list |
| 71 | * |
| 72 | */ |
| 73 | |
| 74 | int |
Rich Lane | 3094326 | 2014-11-07 09:04:13 -0800 | [diff] [blame] | 75 | ${cls}_next(${cls}_t *list, of_object_t *obj) |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 76 | { |
| 77 | int rv; |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 78 | |
| 79 | if ((rv = of_list_next(list, obj)) < 0) { |
| 80 | return rv; |
| 81 | } |
| 82 | |
Rich Lane | 83f958d | 2014-06-13 15:01:40 -0700 | [diff] [blame] | 83 | :: if e_uclass.virtual: |
| 84 | ${e_cls}_wire_object_id_get(obj, &obj->object_id); |
| 85 | :: #endif |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 86 | |
Rich Lane | bbf5e1d | 2014-06-13 15:34:21 -0700 | [diff] [blame] | 87 | :: if wire_length_get != 'NULL': |
| 88 | ${wire_length_get}(obj, &obj->length); |
Rich Lane | 83f958d | 2014-06-13 15:01:40 -0700 | [diff] [blame] | 89 | :: #endif |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 90 | |
| 91 | return rv; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Set up to append an object of type ${e_cls} to an ${cls}. |
| 96 | * @param list The list that is prepared for append |
| 97 | * @param obj Pointer to object to hold data to append |
| 98 | * |
| 99 | * The obj instance is completely initialized. The caller is responsible |
| 100 | * for cleaning up any wire buffers associated with obj before this call. |
| 101 | * |
| 102 | * See the generic documentation for of_list_append_bind. |
| 103 | */ |
| 104 | |
| 105 | int |
Rich Lane | 3094326 | 2014-11-07 09:04:13 -0800 | [diff] [blame] | 106 | ${cls}_append_bind(${cls}_t *list, of_object_t *obj) |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 107 | { |
Rich Lane | 3094326 | 2014-11-07 09:04:13 -0800 | [diff] [blame] | 108 | return of_list_append_bind(list, obj); |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Append an object to a ${cls} list. |
| 113 | * |
| 114 | * This copies data from obj and leaves item untouched. |
| 115 | * |
| 116 | * See the generic documentation for of_list_append. |
| 117 | */ |
| 118 | |
| 119 | int |
Rich Lane | 3094326 | 2014-11-07 09:04:13 -0800 | [diff] [blame] | 120 | ${cls}_append(${cls}_t *list, of_object_t *obj) |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 121 | { |
Rich Lane | 3094326 | 2014-11-07 09:04:13 -0800 | [diff] [blame] | 122 | return of_list_append(list, obj); |
Rich Lane | 99d9a8d | 2014-06-13 14:05:10 -0700 | [diff] [blame] | 123 | } |