[complement-svn] SF.net SVN: complement: [1561] trunk/complement/explore/test/virtual_time
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-05-17 16:26:53
|
Revision: 1561 http://svn.sourceforge.net/complement/?rev=1561&view=rev Author: complement Date: 2007-05-17 09:26:50 -0700 (Thu, 17 May 2007) Log Message: ----------- just development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/Makefile.inc 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/Makefile.inc =================================================================== --- trunk/complement/explore/test/virtual_time/Makefile.inc 2007-05-17 09:15:59 UTC (rev 1560) +++ trunk/complement/explore/test/virtual_time/Makefile.inc 2007-05-17 16:26:50 UTC (rev 1561) @@ -1,4 +1,4 @@ # -*- makefile -*- Time-stamp: <06/10/10 15:22:33 ptr> PRGNAME = vtime -SRC_CC = vtime_main.cc +SRC_CC = vtime_main.cc vtime.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-17 09:15:59 UTC (rev 1560) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-17 16:26:50 UTC (rev 1561) @@ -2,15 +2,68 @@ #include "vtime.h" +#include <stdint.h> + namespace vt { -void Proc::mess( const stem::Event_base<>& ev ) +using namespace std; +using namespace xmt; +using namespace stem; + +void vtime::pack( std::ostream& s ) const { + __pack( s, static_cast<uint8_t>(vt.size()) ); + for ( vtime_type::const_iterator i = vt.begin(); i != vt.end(); ++i ) { + __pack( s, i->first ); + __pack( s, i->second ); + } } +void vtime::net_pack( std::ostream& s ) const +{ + __net_pack( s, static_cast<uint8_t>(vt.size()) ); + for ( vtime_type::const_iterator i = vt.begin(); i != vt.end(); ++i ) { + __net_pack( s, i->first ); + __net_pack( s, i->second ); + } +} + +void vtime::unpack( std::istream& s ) +{ + vt.clear(); + uint8_t n; + __unpack( s, n ); + while ( n-- > 0 ) { + vtime_proc_type v; + + __unpack( s, v.first ); + __unpack( s, v.second ); + + vt.push_back( v ); + } +} + +void vtime::net_unpack( std::istream& s ) +{ + vt.clear(); + uint8_t n; + __net_unpack( s, n ); + while ( n-- > 0 ) { + vtime_proc_type v; + + __net_unpack( s, v.first ); + __net_unpack( s, v.second ); + + vt.push_back( v ); + } +} + +void Proc::mess( const stem::Event_base<vtime>& ev ) +{ +} + DEFINE_RESPONSE_TABLE( Proc ) - EV_Event_base_T_( ST_NULL, MESS, mess, intr::httprq ) + EV_Event_base_T_( ST_NULL, MESS, mess, vtime ) END_RESPONSE_TABLE } // namespace vt - Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-17 09:15:59 UTC (rev 1560) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-17 16:26:50 UTC (rev 1561) @@ -3,12 +3,71 @@ #ifndef __vtime_h #define __vtime_h +#include <algorithm> +#include <list> + +#include <istream> +#include <ostream> +#include <stdexcept> + #include <stem/Event.h> #include <stem/EventHandler.h> namespace vt { -class Proc +typedef unsigned vtime_unit_type; +typedef std::pair<stem::addr_type, vtime_unit_type> vtime_proc_type; +typedef std::list<vtime_proc_type> vtime_type; + +inline bool operator <( const vtime_proc_type& l, const vtime_proc_type& r ) +{ + if ( l.first == r.first ) { + return l.second < r.second; + } + + throw std::invalid_argument( "uncomparable" ); +} + +inline bool operator <=( const vtime_proc_type& l, const vtime_proc_type& r ) +{ + if ( l.first == r.first ) { + return l.second <= r.second; + } + + throw std::invalid_argument( "uncomparable" ); +} + +inline bool operator ==( const vtime_proc_type& l, const vtime_proc_type& r ) +{ + if ( l.first == r.first ) { + return l.second == r.second; + } + + throw std::invalid_argument( "uncomparable" ); +} + + +struct vtime : + 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 ); + + vtime() + { } + vtime( const vtime& _vt ) : + vt( _vt.vt.begin(), _vt.vt.end() ) + { } + + vtime& operator =( const vtime& _vt ) + { vt.clear(); } + + vtime_type vt; +}; + +class Proc : public stem::EventHandler { public: @@ -18,7 +77,7 @@ stem::EventHandler( id ) { } - void mess( const stem::Event_base<>& ); + void mess( const stem::Event_base<vtime>& ); private: 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-17 09:15:59 UTC (rev 1560) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-17 16:26:50 UTC (rev 1561) @@ -1,13 +1,27 @@ #include <iostream> +#include <mt/xmt.h> #include "vtime.h" using namespace std; +using namespace xmt; +using namespace vt; int main() { + Condition cnd; + + cnd.set(false); + cerr << "Hello, world!" << endl; + Proc m1( 100 ); + Proc m2( 101 ); + Proc r1( 102 ); + Proc r3( 103 ); + + cnd.wait(); + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |