Revision: 7554
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7554&view=rev
Author:   rtv
Date:     2009-03-28 00:10:37 +0000 (Sat, 28 Mar 2009)

Log Message:
-----------
cleaned up property API

Modified Paths:
--------------
    code/stage/trunk/libstage/model_load.cc
    code/stage/trunk/libstage/model_props.cc
    code/stage/trunk/libstage/stage.hh

Modified: code/stage/trunk/libstage/model_load.cc
===================================================================
--- code/stage/trunk/libstage/model_load.cc     2009-03-27 23:50:18 UTC (rev 
7553)
+++ code/stage/trunk/libstage/model_load.cc     2009-03-28 00:10:37 UTC (rev 
7554)
@@ -354,31 +354,14 @@
                 assert( type );
                 assert( value );
 
-                //printf( "\nkey: %s type: %s value: %s\n",
-                //             key, type, value );
-                
                 if( strcmp( type, "int" ) == 0 )
-                       {
-                         int* i = new int( atoi(value) );
-                         SetProperty( strdup(key), (void*)i );
-                       }
+                       SetPropertyInt( strdup(key), atoi(value) );
                 else if( strcmp( type, "float" ) == 0 )                        
-                       {
-                         float* f = new float( strtod(value, NULL) );
-                         SetProperty( strdup(key), (void*)f );
-                       }
+                       SetPropertyFloat( strdup(key), strtod(value, NULL) );
                 else if( strcmp( type, "string" ) == 0 )
-                       SetProperty( strdup(key), (void*)strdup(value) );
+                       SetPropertyStr( strdup(key), value );
                 else
-                       PRINT_ERR1( "unknown database entry type \"%s\"\n", 
type );
-                
-//              int* i = (int*)GetProperty( key );
-//              float* f = (float*)GetProperty( key );
-//              char* c = (char*)GetProperty( key );
-
-//              printf( "property %s has int value %d\n", key, *i );
-//              printf( "property %s has float value %.2f\n", key, *f );
-//              printf( "property %s has char* value %s\n", key, c );
+                       PRINT_ERR1( "unknown database entry type \"%s\"\n", 
type );              
          }
 
  }

Modified: code/stage/trunk/libstage/model_props.cc
===================================================================
--- code/stage/trunk/libstage/model_props.cc    2009-03-27 23:50:18 UTC (rev 
7553)
+++ code/stage/trunk/libstage/model_props.cc    2009-03-28 00:10:37 UTC (rev 
7554)
@@ -26,8 +26,8 @@
        return g_datalist_get_data( &this->props, key );
 }
 
-int Model::SetProperty( char* key,
-               void* data )
+int Model::SetProperty( const char* key,
+                                                               const void* 
data )
 {
        // see if the key has the predefined-property prefix
        if( strncmp( key, MP_PREFIX, strlen(MP_PREFIX)) == 0 )
@@ -80,15 +80,74 @@
        }
 
        // otherwise it's an arbitary property and we store the pointer
-       g_datalist_set_data( &this->props, key, data );
+       g_datalist_set_data( &this->props, key, (void*)data );
        return 0; // ok
 }
 
 
-void Model::UnsetProperty( char* key )
+void Model::UnsetProperty( const char* key )
 {
        if( strncmp( key, MP_PREFIX, strlen(MP_PREFIX)) == 0 )
                PRINT_WARN1( "Attempt to unset a model core property \"%s\" has 
no effect", key );
        else
                g_datalist_remove_data( &this->props, key );
 }
+
+
+bool Model::GetPropertyFloat( const char* key, float* f, float defaultval )
+{ 
+  float* fp = (float*)GetProperty( key ); 
+  if( fp )
+        {
+               *f = *fp;
+               return true;
+        }
+  
+  *f = defaultval;
+  return false;
+}
+
+bool Model::GetPropertyInt( const char* key, int* i, int defaultval )
+{ 
+  int* ip = (int*)GetProperty( key ); 
+  if( ip )
+        {
+               *i = *ip;
+               return true;
+        }
+  
+  *i = defaultval;
+  return false;
+}
+
+bool Model::GetPropertyStr( const char* key, char** c, char* defaultval )
+{
+  char* cp = (char*)GetProperty( key ); 
+  
+  if( cp )
+        {
+               *c = cp;
+               return true;
+        }
+  
+  *c = defaultval;
+  return false;
+}
+
+void Model::SetPropertyInt( const char* key, int i )
+{
+  int* ip = new int(i);
+  SetProperty( key, (void*)ip );
+}
+
+void Model::SetPropertyFloat( const char* key, float f )
+{
+  float* fp = new float(f);
+  SetProperty( key, (void*)fp );
+}
+
+void Model::SetPropertyStr( const char* key, const char* str )
+{
+  SetProperty( key, (void*)strdup(str) );
+}
+

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-03-27 23:50:18 UTC (rev 7553)
+++ code/stage/trunk/libstage/stage.hh  2009-03-28 00:10:37 UTC (rev 7554)
@@ -2035,61 +2035,18 @@
         { RemoveCallback( &hooks.save, cb ); }
   
         void AddUpdateCallback( stg_model_callback_t cb, void* user )
-        { 
-               AddCallback( &hooks.update, cb, user ); 
-               //Subscribe(); // if attaching a callback here, assume we want 
updates to happen
-        }
+        {      AddCallback( &hooks.update, cb, user ); }
        
         void RemoveUpdateCallback( stg_model_callback_t cb )
-        { 
-               RemoveCallback( &hooks.update, cb ); 
-               //Unsubscribe();
-        }
+        {      RemoveCallback( &hooks.update, cb ); }
        
         /** named-property interface 
          */
-        void* GetProperty( const char* key );
-        
-        bool GetPropertyFloat( const char* key, float* f, float defaultval )
-        { 
-               float* fp = (float*)GetProperty( key ); 
-               if( fp )
-                 {
-                        *f = *fp;
-                        return true;
-                 }
-               
-               *f = defaultval;
-               return false;
-        }
+        void* GetProperty( const char* key );   
+        bool GetPropertyFloat( const char* key, float* f, float defaultval );  
 
+        bool GetPropertyInt( const char* key, int* i, int defaultval );        
 
+        bool GetPropertyStr( const char* key, char** c, char* defaultval );
 
-        bool GetPropertyInt( const char* key, int* i, int defaultval )
-        { 
-               int* ip = (int*)GetProperty( key ); 
-               if( ip )
-                 {
-                        *i = *ip;
-                        return true;
-                 }
-
-               *i = defaultval;
-               return false;
-        }
-        
-        bool GetPropertyStr( const char* key, char** c, char* defaultval )
-        {
-               char* cp = (char*)GetProperty( key ); 
-
-               if( cp )
-                 {
-                        *c = cp;
-                        return true;
-                 }
-               
-               *c = defaultval;
-               return false;
-        }
-
         /** @brief Set a named property of a Stage model.
         
                  Set a property of a Stage model. 
@@ -2120,8 +2077,12 @@
                  stg_model_set_<property>() function definition to see the type
                  of data required for each property.
         */ 
-        int SetProperty( char* key, void* data );
-        void UnsetProperty( char* key );
+        int SetProperty( const char* key, const void* data );
+        void SetPropertyInt( const char* key, int i );
+        void SetPropertyFloat( const char* key, float f );
+        void SetPropertyStr( const char* key, const char* str );
+        
+        void UnsetProperty( const char* key );
                
         virtual void Print( char* prefix );
         virtual const char* PrintWithPose();


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

------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to