blob: d39af9a7d6fe0ffea2222b593a0368596ffb9d5f [file] [log] [blame]
Rich Lane99d9a8d2014-06-13 14:05:10 -07001:: # 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
44int
Rich Lane7fdaa5c2014-10-27 18:14:59 -070045${cls}_first(${cls}_t *list, of_list_iter_t iter)
Rich Lane99d9a8d2014-06-13 14:05:10 -070046{
47 int rv;
Rich Lane7fdaa5c2014-10-27 18:14:59 -070048 of_object_t *obj = iter.obj;
Rich Lane99d9a8d2014-06-13 14:05:10 -070049
Rich Lane7fdaa5c2014-10-27 18:14:59 -070050 ${e_cls}_init(obj, list->version, -1, 1);
Rich Lane99d9a8d2014-06-13 14:05:10 -070051
52 if ((rv = of_list_first(list, obj)) < 0) {
53 return rv;
54 }
55
Rich Lane83f958d2014-06-13 15:01:40 -070056:: if e_uclass.virtual:
57 ${e_cls}_wire_object_id_get(obj, &obj->object_id);
58:: #endif
59
Rich Lanebbf5e1d2014-06-13 15:34:21 -070060:: if wire_length_get != 'NULL':
61 ${wire_length_get}(obj, &obj->length);
Rich Lane83f958d2014-06-13 15:01:40 -070062:: #endif
Rich Lane99d9a8d2014-06-13 14:05:10 -070063
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
75int
Rich Lane7fdaa5c2014-10-27 18:14:59 -070076${cls}_next(${cls}_t *list, of_list_iter_t iter)
Rich Lane99d9a8d2014-06-13 14:05:10 -070077{
78 int rv;
Rich Lane7fdaa5c2014-10-27 18:14:59 -070079 of_object_t *obj = iter.obj;
Rich Lane99d9a8d2014-06-13 14:05:10 -070080
81 if ((rv = of_list_next(list, obj)) < 0) {
82 return rv;
83 }
84
Rich Lane83f958d2014-06-13 15:01:40 -070085:: if e_uclass.virtual:
86 ${e_cls}_wire_object_id_get(obj, &obj->object_id);
87:: #endif
Rich Lane99d9a8d2014-06-13 14:05:10 -070088
Rich Lanebbf5e1d2014-06-13 15:34:21 -070089:: if wire_length_get != 'NULL':
90 ${wire_length_get}(obj, &obj->length);
Rich Lane83f958d2014-06-13 15:01:40 -070091:: #endif
Rich Lane99d9a8d2014-06-13 14:05:10 -070092
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
107int
Rich Lane7fdaa5c2014-10-27 18:14:59 -0700108${cls}_append_bind(${cls}_t *list, of_list_iter_t iter)
Rich Lane99d9a8d2014-06-13 14:05:10 -0700109{
Rich Lane7fdaa5c2014-10-27 18:14:59 -0700110 return of_list_append_bind(list, iter.obj);
Rich Lane99d9a8d2014-06-13 14:05:10 -0700111}
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
121int
Rich Lane7fdaa5c2014-10-27 18:14:59 -0700122${cls}_append(${cls}_t *list, of_list_iter_t iter)
Rich Lane99d9a8d2014-06-13 14:05:10 -0700123{
Rich Lane7fdaa5c2014-10-27 18:14:59 -0700124 return of_list_append(list, iter.obj);
Rich Lane99d9a8d2014-06-13 14:05:10 -0700125}