commit 1a316c8c9ac1f476f56ce3c19b311e9cdc539ad4 parent f640e3acad3ddba8fa9dd23fc46907bc84a7d916 Author: Michael Savage <mikejsavage@gmail.com> Date: Sun Nov 27 16:05:03 +0200 Make gen_visitors.lua add #pragma once/const visitors Diffstat:
scripts/gen_visitors.lua | | | 9 | +++++++++ |
visitors/linear_algebra.h | | | 67 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- |
diff --git a/scripts/gen_visitors.lua b/scripts/gen_visitors.lua @@ -10,6 +10,8 @@ local output = { " * This file was autogenerated by " .. arg[ 0 ] .. " " .. arg[ 1 ], " * at " .. os.date() .. ". Please do not edit it by hand!", " */", + "", + "#pragma once", } for struct, members in contents:gmatch( "// AUTOVISITOR%s+struct%s+(%w+)%s+(%b{})" ) do @@ -20,6 +22,10 @@ for struct, members in contents:gmatch( "// AUTOVISITOR%s+struct%s+(%w+)%s+(%b{} "template< typename F >", "void visit_members( " .. struct .. " & obj, F f ) {", } + local const_visitor = { + "template< typename F >", + "void visit_members( const " .. struct .. " & obj, F f ) {", + } local named_visitor = { "template< typename F >", "void visit_named_members( " .. struct .. " & obj, F f ) {", @@ -28,13 +34,16 @@ for struct, members in contents:gmatch( "// AUTOVISITOR%s+struct%s+(%w+)%s+(%b{} for names in members:gmatch( "\n\t*%w+%s+([%w, ]+)%s*;" ) do for name in names:gmatch( "(%w+)" ) do table.insert( visitor, "\tf( obj." .. name .. " );" ) + table.insert( const_visitor, "\tf( obj." .. name .. " );" ) table.insert( named_visitor, "\tf( \"" .. name .. "\", obj." .. name .. " );" ) end end table.insert( visitor, "}" ) + table.insert( const_visitor, "}" ) table.insert( named_visitor, "}" ) table.insert( output, "\n" .. table.concat( visitor, "\n" ) ) + table.insert( output, "\n" .. table.concat( const_visitor, "\n" ) ) table.insert( output, "\n" .. table.concat( named_visitor, "\n" ) ) end diff --git a/visitors/linear_algebra.h b/visitors/linear_algebra.h @@ -1,8 +1,10 @@ /* * This file was autogenerated by scripts/gen_visitors.lua linear_algebra.h - * at Tue Nov 22 21:16:20 2016. Please do not edit it by hand! + * at Sun Nov 27 16:04:31 2016. Please do not edit it by hand! */ +#pragma once + template< typename F > void visit_members( v2 & obj, F f ) { f( obj.x ); @@ -10,6 +12,12 @@ void visit_members( v2 & obj, F f ) { } template< typename F > +void visit_members( const v2 & obj, F f ) { + f( obj.x ); + f( obj.y ); +} + +template< typename F > void visit_named_members( v2 & obj, F f ) { f( "x", obj.x ); f( "y", obj.y ); @@ -22,6 +30,12 @@ void visit_members( v2s32 & obj, F f ) { } template< typename F > +void visit_members( const v2s32 & obj, F f ) { + f( obj.x ); + f( obj.y ); +} + +template< typename F > void visit_named_members( v2s32 & obj, F f ) { f( "x", obj.x ); f( "y", obj.y ); @@ -34,6 +48,12 @@ void visit_members( m2 & obj, F f ) { } template< typename F > +void visit_members( const m2 & obj, F f ) { + f( obj.row0 ); + f( obj.row1 ); +} + +template< typename F > void visit_named_members( m2 & obj, F f ) { f( "row0", obj.row0 ); f( "row1", obj.row1 ); @@ -47,6 +67,13 @@ void visit_members( v3 & obj, F f ) { } template< typename F > +void visit_members( const v3 & obj, F f ) { + f( obj.x ); + f( obj.y ); + f( obj.z ); +} + +template< typename F > void visit_named_members( v3 & obj, F f ) { f( "x", obj.x ); f( "y", obj.y ); @@ -61,6 +88,13 @@ void visit_members( v3u32 & obj, F f ) { } template< typename F > +void visit_members( const v3u32 & obj, F f ) { + f( obj.x ); + f( obj.y ); + f( obj.z ); +} + +template< typename F > void visit_named_members( v3u32 & obj, F f ) { f( "x", obj.x ); f( "y", obj.y ); @@ -75,6 +109,13 @@ void visit_members( m3 & obj, F f ) { } template< typename F > +void visit_members( const m3 & obj, F f ) { + f( obj.row0 ); + f( obj.row1 ); + f( obj.row2 ); +} + +template< typename F > void visit_named_members( m3 & obj, F f ) { f( "row0", obj.row0 ); f( "row1", obj.row1 ); @@ -90,6 +131,14 @@ void visit_members( v4 & obj, F f ) { } template< typename F > +void visit_members( const v4 & obj, F f ) { + f( obj.x ); + f( obj.y ); + f( obj.z ); + f( obj.w ); +} + +template< typename F > void visit_named_members( v4 & obj, F f ) { f( "x", obj.x ); f( "y", obj.y ); @@ -106,6 +155,14 @@ void visit_members( m4 & obj, F f ) { } template< typename F > +void visit_members( const m4 & obj, F f ) { + f( obj.row0 ); + f( obj.row1 ); + f( obj.row2 ); + f( obj.row3 ); +} + +template< typename F > void visit_named_members( m4 & obj, F f ) { f( "row0", obj.row0 ); f( "row1", obj.row1 ); @@ -122,6 +179,14 @@ void visit_members( quat & obj, F f ) { } template< typename F > +void visit_members( const quat & obj, F f ) { + f( obj.x ); + f( obj.y ); + f( obj.z ); + f( obj.w ); +} + +template< typename F > void visit_named_members( quat & obj, F f ) { f( "x", obj.x ); f( "y", obj.y );