Revision: 7711
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7711&view=rev
Author:   rtv
Date:     2009-05-23 00:19:58 +0000 (Sat, 23 May 2009)

Log Message:
-----------
moved to more STL containers

Modified Paths:
--------------
    code/websim/examples/world.fed
    code/websim/src/confederate.cc
    code/websim/src/parser.cc
    code/websim/src/puppet.cc
    code/websim/src/websim.cc
    code/websim/src/websim.hh

Modified: code/websim/examples/world.fed
===================================================================
--- code/websim/examples/world.fed      2009-05-22 21:57:22 UTC (rev 7710)
+++ code/websim/examples/world.fed      2009-05-23 00:19:58 UTC (rev 7711)
@@ -2,13 +2,16 @@
 [federation]
 deckard:8000=master
 deckard:8001=slave1
-deckard:8002=slave2
-deckard:8003=slave3
+#deckard:8002=slave2
+#deckard:8003=slave3
 
 [master]
-monkey=slave1:pioneer2dx;slave2:pioneer2dx
-chunky=slave1:pioneer2dx;slave2:pioneer2dx
-punky=slave1:pioneer2dx;slave2:pioneer2dx
+#monkey=slave1:pioneer2dx;slave2:pioneer2dx
+#chunky=slave1:pioneer2dx;slave2:pioneer2dx
+#punky=slave1:pioneer2dx;slave2:pioneer2dx
+monkey=slave1:pioneer2dx
+chunky=slave1:pioneer2dx
+punky=slave1:pioneer2dx
 
 
 

Modified: code/websim/src/confederate.cc
===================================================================
--- code/websim/src/confederate.cc      2009-05-22 21:57:22 UTC (rev 7710)
+++ code/websim/src/confederate.cc      2009-05-23 00:19:58 UTC (rev 7711)
@@ -189,8 +189,7 @@
   while( ! puppet->created )
         event_loop( EVLOOP_ONCE ); // loops until the request has completed
   
-  puppet_list = 
-        g_list_append( puppet_list, puppet );                                  
                                                 
+  puppet_list.push_back( puppet );
 }
 
 void WebSim::Confederate::PuppetPushCallback( evhttp_request* req, void* arg )

Modified: code/websim/src/parser.cc
===================================================================
--- code/websim/src/parser.cc   2009-05-22 21:57:22 UTC (rev 7710)
+++ code/websim/src/parser.cc   2009-05-23 00:19:58 UTC (rev 7711)
@@ -85,7 +85,8 @@
                         assert(conf);
                         
                         // copy the hash table key so we can delete the 
original below
-                        g_hash_table_insert( confederates, 
strdup(logicalname), conf );
+                        //g_hash_table_insert( confederates, 
strdup(logicalname), conf );
+                        confederates[ logicalname ] = conf;
                  }
         }
   

Modified: code/websim/src/puppet.cc
===================================================================
--- code/websim/src/puppet.cc   2009-05-22 21:57:22 UTC (rev 7710)
+++ code/websim/src/puppet.cc   2009-05-23 00:19:58 UTC (rev 7711)
@@ -38,18 +38,23 @@
   created( false ),
   confederates( NULL )
 {
-  g_hash_table_insert( ws->puppets, (void*)this->name.c_str(), this );
+  ws->puppets[name] = this;
   printf( "Puppet \"%s\" constructed\n", this->name.c_str() );
 }
 
+WebSim::Puppet::~Puppet() 
+{
+  ws->puppets.erase( name );
+}
+
 void WebSim::Puppet::Push( Pose p, Velocity v, Acceleration a )
 {
-  for( GList* it = confederates;
-                it;
-                it = it->next )
+  for( std::list<Confederate*>::iterator it = confederates.begin();
+                it != confederates.end();
+                ++it )
         {
-               Confederate* conf = (Confederate*)it->data;
-               conf->Push( name, p, v, a );              
+               //              Confederate* conf = (Confederate*)it->data;
+               (*it)->Push( name, p, v, a );             
         }
 }
 
@@ -57,7 +62,8 @@
                                                                                
                 const std::string& prototype )
 {
   conf->AddPuppet( this, prototype );  
-  confederates = g_list_append( confederates, conf );
+  //confederates = g_list_append( confederates, conf );
+  confederates.push_back( conf );
 }
 
 

Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc   2009-05-22 21:57:22 UTC (rev 7710)
+++ code/websim/src/websim.cc   2009-05-23 00:19:58 UTC (rev 7711)
@@ -58,9 +58,11 @@
   ticks_remaining(0),
   host(_host), 
   port(_port),
-  puppets( g_hash_table_new( g_str_hash, g_str_equal ) ),
-  confederates( g_hash_table_new( g_str_hash, g_str_equal ) ),
-  logical_hosts( g_hash_table_new( g_str_hash, g_str_equal ) ),
+  //puppets( g_hash_table_new( g_str_hash, g_str_equal ) ),
+  //confederates( g_hash_table_new( g_str_hash, g_str_equal ) ),
+  //logical_hosts( g_hash_table_new( g_str_hash, g_str_equal ) ),
+  puppets(),
+  confederates(),  
   unacknowledged_pushes(0),
   unacknowledged_ticks(0),
   total_ticks(0)
@@ -105,7 +107,12 @@
 WebSim::Go()
 {
   // tick all my confederates
-  ForEachConfederate( Confederate::TickCb, NULL );  
+  //ForEachConfederate( Confederate::TickCb, NULL );  
+
+  for( std::map<std::string,Confederate*>::iterator it = confederates.begin();
+                it != confederates.end();
+                it++ )
+        it->second->Tick();
 }
 
 void
@@ -987,26 +994,28 @@
   return false;
 }
 
-void WebSim::ForEachConfederate(  void(*cb)(const std::string&, 
WebSim::Confederate*, void*), void* arg )
-{
-  g_hash_table_foreach( WebSim::confederates,
-                                                               (GHFunc)cb, 
-                                                               arg );
-}
+// void WebSim::ForEachConfederate(  void(*cb)(const std::string&, 
WebSim::Confederate*, void*), void* arg )
+// {
+//   g_hash_table_foreach( WebSim::confederates,
+//                                                             (GHFunc)cb, 
+//                                                             arg );
+// }
 
-void WebSim::ForEachPuppet( void(*cb)(const std::string&, WebSim::Puppet*, 
void*), void* arg )
-{
-  g_hash_table_foreach( WebSim::puppets,
-                                                               (GHFunc)cb, 
-                                                               arg );
-}
+// void WebSim::ForEachPuppet( void(*cb)(const std::string&, WebSim::Puppet*, 
void*), void* arg )
+// {
+//   g_hash_table_foreach( WebSim::puppets,
+//                                                             (GHFunc)cb, 
+//                                                             arg );
+// }
 
 WebSim::Puppet* WebSim::GetPuppet( const std::string& name )
 {
-  return( (Puppet*)g_hash_table_lookup( WebSim::puppets, name.c_str() ) );
+  //return( (Puppet*)g_hash_table_lookup( WebSim::puppets, name.c_str() ) );
+  return puppets[name];
 }
 
 WebSim::Confederate* WebSim::GetConfederate( const std::string& name )
 {
-  return( (Confederate*)g_hash_table_lookup( WebSim::confederates, 
name.c_str() ) );
+  //return( (Confederate*)g_hash_table_lookup( WebSim::confederates, 
name.c_str() ) );
+  return confederates[name];
 }

Modified: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh   2009-05-22 21:57:22 UTC (rev 7710)
+++ code/websim/src/websim.hh   2009-05-23 00:19:58 UTC (rev 7711)
@@ -28,6 +28,7 @@
 #include <string>
 #include <vector>
 #include <map>
+#include <list>
 
 // These headers must be included prior to the libevent headers
 #include <sys/types.h>
@@ -225,7 +226,8 @@
         
   public:  
         Puppet( WebSim* ws, const std::string& name );
-        
+        ~Puppet();
+
         // unique ID used as a system-wide handle for this puppet, used as
         // hash table key
         std::string name;
@@ -233,8 +235,9 @@
         bool created;
         
         // the remote servers that are hosting an instance of this puppet
-        GList* confederates;
-        
+        //GList* confederates;
+        std::list<Confederate*> confederates;
+
         // sends the current physical state of the puppet to all
         // confederates
         void Push( Pose p, Velocity v, Acceleration a );
@@ -275,22 +278,22 @@
         
         // list of pointers to Puppet objects that are hosted on this
         // connection - can iterate over these to update all puppets
-        GList* puppet_list;
-        
+        //GList* puppet_list;
+        std::list<Puppet*> puppet_list;
+
         // unique ID for this confederate in format "hostname:port", used as
         // hash table key
         std::string name;  
   };
   
- private:
-  // static const unsigned short DEFAULT_PORT;
+ protected:
+// static const unsigned short DEFAULT_PORT;
   static const std::string package;
   static const std::string version;
-    
-  GHashTable* puppets;
-  GHashTable* confederates;
-  GHashTable* logical_hosts;
 
+  std::map<std::string,Puppet*> puppets;
+  std::map<std::string,Confederate*> confederates;
+
   // counts the number of status messages sent and replies not yet received
   int unacknowledged_pushes;
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to