medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 9da810e7ffd85a1ed612686edaed39ac723ab0eb
parent 16f90461a0c07a989fa7e8797e1649f6daf2dcb6
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu Dec 22 22:24:00 +0200

gen_visitors improvements

- Drop visit_named_members
- Rename visit_members to visit
- Make visit recursive

Diffstat:
scripts/gen_visitors.lua | 15++++-----------
visitors/linear_algebra.h | 207++++++++++++++++++++++++++++---------------------------------------------------
2 files changed, 76 insertions(+), 146 deletions(-)
diff --git a/scripts/gen_visitors.lua b/scripts/gen_visitors.lua @@ -19,31 +19,24 @@ for struct, members in contents:gmatch( "// AUTOVISITOR%s+struct%s+(%w+)%s+(%b{} local visitor = { "template< typename F >", - "void visit_members( " .. struct .. " & obj, F f ) {", + "void visit( " .. 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 ) {", + "void visit( const " .. struct .. " & obj, F f ) {", } 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 .. " );" ) + table.insert( visitor, "\tvisit( obj." .. name .. ", f );" ) + table.insert( const_visitor, "\tvisit( obj." .. name .. ", f );" ) 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 print( table.concat( output, "\n" ) ) diff --git a/visitors/linear_algebra.h b/visitors/linear_algebra.h @@ -5,190 +5,127 @@ #pragma once template< typename F > -void visit_members( v2 & obj, F f ) { - f( obj.x ); - f( obj.y ); +void visit( v2 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); } template< typename F > -void visit_members( const v2 & obj, F f ) { - f( obj.x ); - f( obj.y ); +void visit( const v2 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); } template< typename F > -void visit_named_members( v2 & obj, F f ) { - f( "x", obj.x ); - f( "y", obj.y ); +void visit( v2s32 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); } template< typename F > -void visit_members( v2s32 & obj, F f ) { - f( obj.x ); - f( obj.y ); +void visit( const v2s32 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); } template< typename F > -void visit_members( const v2s32 & obj, F f ) { - f( obj.x ); - f( obj.y ); +void visit( m2 & obj, F f ) { + visit( obj.row0, f ); + visit( obj.row1, f ); } template< typename F > -void visit_named_members( v2s32 & obj, F f ) { - f( "x", obj.x ); - f( "y", obj.y ); +void visit( const m2 & obj, F f ) { + visit( obj.row0, f ); + visit( obj.row1, f ); } template< typename F > -void visit_members( m2 & obj, F f ) { - f( obj.row0 ); - f( obj.row1 ); +void visit( v3 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); + visit( obj.z, f ); } template< typename F > -void visit_members( const m2 & obj, F f ) { - f( obj.row0 ); - f( obj.row1 ); +void visit( const v3 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); + visit( obj.z, f ); } template< typename F > -void visit_named_members( m2 & obj, F f ) { - f( "row0", obj.row0 ); - f( "row1", obj.row1 ); +void visit( v3u32 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); + visit( obj.z, f ); } template< typename F > -void visit_members( v3 & obj, F f ) { - f( obj.x ); - f( obj.y ); - f( obj.z ); +void visit( const v3u32 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); + visit( obj.z, f ); } template< typename F > -void visit_members( const v3 & obj, F f ) { - f( obj.x ); - f( obj.y ); - f( obj.z ); +void visit( m3 & obj, F f ) { + visit( obj.row0, f ); + visit( obj.row1, f ); + visit( obj.row2, f ); } template< typename F > -void visit_named_members( v3 & obj, F f ) { - f( "x", obj.x ); - f( "y", obj.y ); - f( "z", obj.z ); +void visit( const m3 & obj, F f ) { + visit( obj.row0, f ); + visit( obj.row1, f ); + visit( obj.row2, f ); } template< typename F > -void visit_members( v3u32 & obj, F f ) { - f( obj.x ); - f( obj.y ); - f( obj.z ); +void visit( v4 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); + visit( obj.z, f ); + visit( obj.w, f ); } template< typename F > -void visit_members( const v3u32 & obj, F f ) { - f( obj.x ); - f( obj.y ); - f( obj.z ); +void visit( const v4 & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); + visit( obj.z, f ); + visit( obj.w, f ); } template< typename F > -void visit_named_members( v3u32 & obj, F f ) { - f( "x", obj.x ); - f( "y", obj.y ); - f( "z", obj.z ); +void visit( m4 & obj, F f ) { + visit( obj.row0, f ); + visit( obj.row1, f ); + visit( obj.row2, f ); + visit( obj.row3, f ); } template< typename F > -void visit_members( m3 & obj, F f ) { - f( obj.row0 ); - f( obj.row1 ); - f( obj.row2 ); +void visit( const m4 & obj, F f ) { + visit( obj.row0, f ); + visit( obj.row1, f ); + visit( obj.row2, f ); + visit( obj.row3, f ); } template< typename F > -void visit_members( const m3 & obj, F f ) { - f( obj.row0 ); - f( obj.row1 ); - f( obj.row2 ); +void visit( quat & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); + visit( obj.z, f ); + visit( obj.w, f ); } template< typename F > -void visit_named_members( m3 & obj, F f ) { - f( "row0", obj.row0 ); - f( "row1", obj.row1 ); - f( "row2", obj.row2 ); -} - -template< typename F > -void visit_members( v4 & obj, F f ) { - f( obj.x ); - f( obj.y ); - f( obj.z ); - f( obj.w ); -} - -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 ); - f( "z", obj.z ); - f( "w", obj.w ); -} - -template< typename F > -void visit_members( m4 & obj, F f ) { - f( obj.row0 ); - f( obj.row1 ); - f( obj.row2 ); - f( obj.row3 ); -} - -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 ); - f( "row2", obj.row2 ); - f( "row3", obj.row3 ); -} - -template< typename F > -void visit_members( quat & obj, F f ) { - f( obj.x ); - f( obj.y ); - f( obj.z ); - f( obj.w ); -} - -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 ); - f( "z", obj.z ); - f( "w", obj.w ); +void visit( const quat & obj, F f ) { + visit( obj.x, f ); + visit( obj.y, f ); + visit( obj.z, f ); + visit( obj.w, f ); }