blob: dd69df0986e73ae5f058793e967c64749a9b6f97 [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
45${cls}_first(${cls}_t *list, ${e_cls}_t *_obj)
46{
47 int rv;
48 of_object_t *obj = (of_object_t *)_obj;
49
50 ${e_cls}_init(_obj, list->version, 0, 1);
51
52 if ((rv = of_list_first(list, obj)) < 0) {
53 return rv;
54 }
55
56 of_object_wire_init(obj, ${e_cls.upper()}, list->length);
57 if (obj->length == 0) {
58 return OF_ERROR_PARSE;
59 }
60
61 return rv;
62}
63
64/**
65 * Advance an iterator to the next element in a list
66 * @param list The list being iterated
67 * @param obj The list entry iteration pointer
68 * @return OF_ERROR_RANGE if already at the last entry on the list
69 *
70 */
71
72int
73${cls}_next(${cls}_t *list, ${e_cls}_t *_obj)
74{
75 int rv;
76 of_object_t *obj = (of_object_t *)_obj;
77
78 if ((rv = of_list_next(list, obj)) < 0) {
79 return rv;
80 }
81
82 rv = of_object_wire_init(obj, ${e_cls.upper()}, list->length);
83
84 if ((rv == OF_ERROR_NONE) && (obj->length == 0)) {
85 return OF_ERROR_PARSE;
86 }
87
88 return rv;
89}
90
91/**
92 * Set up to append an object of type ${e_cls} to an ${cls}.
93 * @param list The list that is prepared for append
94 * @param obj Pointer to object to hold data to append
95 *
96 * The obj instance is completely initialized. The caller is responsible
97 * for cleaning up any wire buffers associated with obj before this call.
98 *
99 * See the generic documentation for of_list_append_bind.
100 */
101
102int
103${cls}_append_bind(${cls}_t *list, ${e_cls}_t *obj)
104{
105 return of_list_append_bind(list, (of_object_t *)obj);
106}
107
108/**
109 * Append an object to a ${cls} list.
110 *
111 * This copies data from obj and leaves item untouched.
112 *
113 * See the generic documentation for of_list_append.
114 */
115
116int
117${cls}_append(${cls}_t *list, ${e_cls}_t *obj)
118{
119 return of_list_append(list, (of_object_t *)obj);
120}