[complement-svn] SF.net SVN: complement: [1565] trunk/complement/explore/test/virtual_time
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-05-18 15:34:09
|
Revision: 1565 http://svn.sourceforge.net/complement/?rev=1565&view=rev Author: complement Date: 2007-05-18 08:34:06 -0700 (Fri, 18 May 2007) Log Message: ----------- development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-18 07:19:24 UTC (rev 1564) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-18 15:34:06 UTC (rev 1565) @@ -2,6 +2,7 @@ #include "vtime.h" +#include <iostream> #include <stdint.h> namespace vt { @@ -58,6 +59,72 @@ } } +void gvtime::pack( std::ostream& s ) const +{ + __pack( s, static_cast<uint8_t>(gvt.size()) ); + for ( gvtime_type::const_iterator i = gvt.begin(); i != gvt.end(); ++i ) { + __pack( s, i->first ); + i->second.pack( s ); + } +} + +void gvtime::net_pack( std::ostream& s ) const +{ + __net_pack( s, static_cast<uint8_t>(gvt.size()) ); + for ( gvtime_type::const_iterator i = gvt.begin(); i != gvt.end(); ++i ) { + __net_pack( s, i->first ); + i->second.net_pack( s ); + } +} + +void gvtime::unpack( std::istream& s ) +{ + gvt.clear(); + uint8_t n; + __unpack( s, n ); + while ( n-- > 0 ) { + gvt.push_back( vtime_group_type() ); + __unpack( s, gvt.back().first ); + gvt.back().second.unpack( s ); + } +} + +void gvtime::net_unpack( std::istream& s ) +{ + gvt.clear(); + uint8_t n; + __net_unpack( s, n ); + while ( n-- > 0 ) { + gvt.push_back( vtime_group_type() ); + __net_unpack( s, gvt.back().first ); + gvt.back().second.net_unpack( s ); + } +} + +void VTmess::pack( std::ostream& s ) const +{ + gvt.pack( s ); + __pack( s, mess ); +} + +void VTmess::net_pack( std::ostream& s ) const +{ + gvt.net_pack( s ); + __net_pack( s, mess ); +} + +void VTmess::unpack( std::istream& s ) +{ + gvt.unpack( s ); + __unpack( s, mess ); +} + +void VTmess::net_unpack( std::istream& s ) +{ + gvt.net_unpack( s ); + __net_unpack( s, mess ); +} + vtime_type operator -( const vtime_type& l, const vtime_type& r ) { if ( r.empty() ) { @@ -97,12 +164,13 @@ } -void Proc::mess( const stem::Event_base<vtime>& ev ) +void Proc::mess( const stem::Event_base<VTmess>& ev ) { + cout << ev.value().mess << endl; } DEFINE_RESPONSE_TABLE( Proc ) - EV_Event_base_T_( ST_NULL, MESS, mess, vtime ) + EV_Event_base_T_( ST_NULL, MESS, mess, VTmess ) END_RESPONSE_TABLE } // namespace vt Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-18 07:19:24 UTC (rev 1564) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-18 15:34:06 UTC (rev 1565) @@ -5,6 +5,8 @@ #include <algorithm> #include <list> +#include <vector> +#include <iterator> #include <istream> #include <ostream> @@ -16,6 +18,7 @@ namespace vt { typedef unsigned vtime_unit_type; +typedef uint32_t group_type; typedef std::pair<stem::addr_type, vtime_unit_type> vtime_proc_type; typedef std::list<vtime_proc_type> vtime_type; @@ -106,11 +109,54 @@ { } vtime& operator =( const vtime& _vt ) - { vt.clear(); } + { vt.clear(); std::copy( _vt.vt.begin(), _vt.vt.end(), std::back_insert_iterator<vtime_type>(vt) ); } vtime_type vt; }; +typedef std::pair<group_type, vtime> vtime_group_type; +typedef std::list<vtime_group_type> gvtime_type; + +struct gvtime : + public stem::__pack_base +{ + void pack( std::ostream& s ) const; + void net_pack( std::ostream& s ) const; + void unpack( std::istream& s ); + void net_unpack( std::istream& s ); + + gvtime() + { } + gvtime( const gvtime& _gvt ) : + gvt( _gvt.gvt.begin(), _gvt.gvt.end() ) + { } + + gvtime& operator =( const gvtime& _gvt ) + { gvt.clear(); std::copy( _gvt.gvt.begin(), _gvt.gvt.end(), std::back_insert_iterator<gvtime_type>(gvt) ); } + + gvtime_type gvt; +}; + +struct VTmess : + public stem::__pack_base +{ + void pack( std::ostream& s ) const; + void net_pack( std::ostream& s ) const; + void unpack( std::istream& s ); + void net_unpack( std::istream& s ); + + VTmess() + { } + VTmess( const VTmess& _gvt ) : + gvt( _gvt.gvt ), + mess( _gvt.mess ) + { } + + gvtime gvt; + std::string mess; +}; + + class Proc : public stem::EventHandler { @@ -121,9 +167,18 @@ stem::EventHandler( id ) { } - void mess( const stem::Event_base<vtime>& ); + void mess( const stem::Event_base<VTmess>& ); private: + + enum vtgroup { + first_group, + second_group, + n_groups + }; + + std::vector<vtime> vt[n_groups]; + DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); }; Modified: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-18 07:19:24 UTC (rev 1564) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-18 15:34:06 UTC (rev 1565) @@ -20,6 +20,13 @@ Proc r1( 102 ); Proc r3( 103 ); + stem::Event_base<VTmess> mess( MESS ); + + mess.dest( 101 ); + mess.value().mess = "Hello!"; + + m1.Send( mess ); + cnd.wait(); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |