loci: generate list accessors with a template

Still uses the legacy code to figure out which lists to generate.
diff --git a/c_gen/c_code_gen.py b/c_gen/c_code_gen.py
index e4e2403..6ff2010 100644
--- a/c_gen/c_code_gen.py
+++ b/c_gen/c_code_gen.py
@@ -1081,172 +1081,6 @@
 
 ################################################################
 #
-# List accessor code generation
-#
-# Currently these all implement copy on read semantics
-#
-################################################################
-
-def init_call(e_type, obj, ver, length, cw):
-    """
-    Generate the init call given the strings for params
-    """
-    hdr = "" # If inheritance type, coerce to hdr object
-    obj_name = obj
-    if e_type in type_maps.inheritance_map:
-        hdr = "_header"
-        obj_name = "(%s_header_t *)" % e_type + obj
-
-    return """\
-%(e_type)s%(hdr)s_init(%(obj_name)s,
-            %(ver)s, %(length)s, %(cw)s)\
-""" % dict(e_type=e_type, hdr=hdr, obj_name=obj_name, ver=ver,
-           length=length, cw=cw)
-
-def gen_list_first(out, cls, e_type):
-    """
-    Generate the body of a list_first operation
-    @param cls The class name for which code is being generated
-    @param e_type The element type of the list
-    @param out The file to which to write
-    """
-    i_call = init_call(e_type, "obj", "list->version", "0", "1")
-    if e_type in type_maps.inheritance_map:
-        len_str = "obj->header.length"
-    else:
-        len_str = "obj->length"
-
-    out.write("""
-/**
- * Associate an iterator with a list
- * @param list The list to iterate over
- * @param obj The list entry iteration pointer
- * @return OF_ERROR_RANGE if the list is empty (end of list)
- *
- * The obj instance is completely initialized.  The caller is responsible
- * for cleaning up any wire buffers associated with obj before this call
- */
-
-int
-%(cls)s_first(%(cls)s_t *list,
-    %(e_type)s_t *obj)
-{
-    int rv;
-
-    %(i_call)s;
-    if ((rv = of_list_first((of_object_t *)list, (of_object_t *)obj)) < 0) {
-        return rv;
-    }
-""" % dict(cls=cls, e_type=e_type, i_call=i_call))
-
-    # Special case flow_stats_entry lists
-
-    out.write("""
-    of_object_wire_init((of_object_t *) obj, %(u_type)s,
-                        list->length);
-    if (%(len_str)s == 0) {
-        return OF_ERROR_PARSE;
-    }
-
-    return rv;
-}
-""" % dict(cls=cls, e_type=e_type, u_type=enum_name(e_type), len_str=len_str))
-
-def gen_list_next(out, cls, e_type):
-    """
-    Generate the body of a list_next operation
-    @param cls The class name for which code is being generated
-    @param e_type The element type of the list
-    @param out The file to which to write
-    """
-
-    if e_type in type_maps.inheritance_map:
-        len_str = "obj->header.length"
-    else:
-        len_str = "obj->length"
-
-    out.write("""
-/**
- * Advance an iterator to the next element in a list
- * @param list The list being iterated
- * @param obj The list entry iteration pointer
- * @return OF_ERROR_RANGE if already at the last entry on the list
- *
- */
-
-int
-%(cls)s_next(%(cls)s_t *list,
-    %(e_type)s_t *obj)
-{
-    int rv;
-
-    if ((rv = of_list_next((of_object_t *)list, (of_object_t *)obj)) < 0) {
-        return rv;
-    }
-
-    rv = of_object_wire_init((of_object_t *) obj, %(u_type)s,
-        list->length);
-
-    if ((rv == OF_ERROR_NONE) && (%(len_str)s == 0)) {
-        return OF_ERROR_PARSE;
-    }
-
-    return rv;
-}
-""" % dict(cls=cls, e_type=e_type, u_type=enum_name(e_type), len_str=len_str))
-
-def gen_list_append(out, cls, e_type):
-    """
-    Generate the body of a list append functions
-    @param cls The class name for which code is being generated
-    @param e_type The element type of the list
-    @param out The file to which to write
-    """
-
-    out.write("""
-/**
- * Set up to append an object of type %(e_type)s to an %(cls)s.
- * @param list The list that is prepared for append
- * @param obj Pointer to object to hold data to append
- *
- * The obj instance is completely initialized.  The caller is responsible
- * for cleaning up any wire buffers associated with obj before this call.
- *
- * See the generic documentation for of_list_append_bind.
- */
-
-int
-%(cls)s_append_bind(%(cls)s_t *list,
-    %(e_type)s_t *obj)
-{
-    return of_list_append_bind((of_object_t *)list, (of_object_t *)obj);
-}
-
-/**
- * Append an item to a %(cls)s list.
- *
- * This copies data from item and leaves item untouched.
- *
- * See the generic documentation for of_list_append.
- */
-
-int
-%(cls)s_append(%(cls)s_t *list,
-    %(e_type)s_t *item)
-{
-    return of_list_append((of_object_t *)list, (of_object_t *)item);
-}
-
-""" % dict(cls=cls, e_type=e_type))
-
-def gen_list_accessors(out, cls):
-    e_type = loxi_utils.list_to_entry_type(cls)
-    gen_list_first(out, cls, e_type)
-    gen_list_next(out, cls, e_type)
-    gen_list_append(out, cls, e_type)
-
-################################################################
-#
 # Accessor Functions
 #
 ################################################################
diff --git a/c_gen/codegen.py b/c_gen/codegen.py
index 7cb46db..e2646e4 100644
--- a/c_gen/codegen.py
+++ b/c_gen/codegen.py
@@ -43,6 +43,7 @@
 import c_gen.of_g_legacy as of_g
 import c_gen.type_maps as type_maps
 import c_gen.c_type_maps as c_type_maps
+import c_gen.loxi_utils_legacy as loxi_utils
 
 CLASS_CHUNK_SIZE = 32
 
@@ -147,12 +148,10 @@
 def generate_lists(install_dir):
     for cls in of_g.ordered_list_objects:
         with template_utils.open_output(install_dir, "loci/src/%s.c" % cls) as out:
-            util.render_template(out, "class.c",
-                push_wire_types_data=None,
-                parse_wire_types_data=None)
+            e_cls = loxi_utils.list_to_entry_type(cls)
+            util.render_template(out, "list.c", cls=cls, e_cls=e_cls)
             # Append legacy generated code
             c_code_gen.gen_new_function_definitions(out, cls)
-            c_code_gen.gen_list_accessors(out, cls)
 
 def generate_strings(install_dir):
     object_id_strs = []
diff --git a/c_gen/templates/list.c b/c_gen/templates/list.c
new file mode 100644
index 0000000..dd69df0
--- /dev/null
+++ b/c_gen/templates/list.c
@@ -0,0 +1,120 @@
+:: # Copyright 2014, Big Switch Networks, Inc.
+:: #
+:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
+:: # the following special exception:
+:: #
+:: # LOXI Exception
+:: #
+:: # As a special exception to the terms of the EPL, you may distribute libraries
+:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
+:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
+:: # from the LoxiGen Libraries and the notice provided below is (i) included in
+:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
+:: # documentation for the LoxiGen Libraries, if distributed in binary form.
+:: #
+:: # Notice: "Copyright 2014, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
+:: #
+:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
+:: # a copy of the EPL at:
+:: #
+:: # http://www.eclipse.org/legal/epl-v10.html
+:: #
+:: # Unless required by applicable law or agreed to in writing, software
+:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+:: # EPL for the specific language governing permissions and limitations
+:: # under the EPL.
+::
+:: include('_copyright.c')
+:: include('_pragmas.c')
+
+#include "loci_log.h"
+#include "loci_int.h"
+
+/**
+ * Associate an iterator with a list
+ * @param list The list to iterate over
+ * @param obj The list entry iteration pointer
+ * @return OF_ERROR_RANGE if the list is empty (end of list)
+ *
+ * The obj instance is completely initialized.  The caller is responsible
+ * for cleaning up any wire buffers associated with obj before this call
+ */
+
+int
+${cls}_first(${cls}_t *list, ${e_cls}_t *_obj)
+{
+    int rv;
+    of_object_t *obj = (of_object_t *)_obj;
+
+    ${e_cls}_init(_obj, list->version, 0, 1);
+
+    if ((rv = of_list_first(list, obj)) < 0) {
+        return rv;
+    }
+
+    of_object_wire_init(obj, ${e_cls.upper()}, list->length);
+    if (obj->length == 0) {
+        return OF_ERROR_PARSE;
+    }
+
+    return rv;
+}
+
+/**
+ * Advance an iterator to the next element in a list
+ * @param list The list being iterated
+ * @param obj The list entry iteration pointer
+ * @return OF_ERROR_RANGE if already at the last entry on the list
+ *
+ */
+
+int
+${cls}_next(${cls}_t *list, ${e_cls}_t *_obj)
+{
+    int rv;
+    of_object_t *obj = (of_object_t *)_obj;
+
+    if ((rv = of_list_next(list, obj)) < 0) {
+        return rv;
+    }
+
+    rv = of_object_wire_init(obj, ${e_cls.upper()}, list->length);
+
+    if ((rv == OF_ERROR_NONE) && (obj->length == 0)) {
+        return OF_ERROR_PARSE;
+    }
+
+    return rv;
+}
+
+/**
+ * Set up to append an object of type ${e_cls} to an ${cls}.
+ * @param list The list that is prepared for append
+ * @param obj Pointer to object to hold data to append
+ *
+ * The obj instance is completely initialized.  The caller is responsible
+ * for cleaning up any wire buffers associated with obj before this call.
+ *
+ * See the generic documentation for of_list_append_bind.
+ */
+
+int
+${cls}_append_bind(${cls}_t *list, ${e_cls}_t *obj)
+{
+    return of_list_append_bind(list, (of_object_t *)obj);
+}
+
+/**
+ * Append an object to a ${cls} list.
+ *
+ * This copies data from obj and leaves item untouched.
+ *
+ * See the generic documentation for of_list_append.
+ */
+
+int
+${cls}_append(${cls}_t *list, ${e_cls}_t *obj)
+{
+    return of_list_append(list, (of_object_t *)obj);
+}