Revision: 8248
http://playerstage.svn.sourceforge.net/playerstage/?rev=8248&view=rev
Author: rtv
Date: 2009-09-08 01:38:21 +0000 (Tue, 08 Sep 2009)
Log Message:
-----------
added checking for correct vector sizes in world files for size and pose
properties
Modified Paths:
--------------
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_load.cc
code/stage/trunk/libstage/worldfile.cc
code/stage/trunk/libstage/worldfile.hh
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2009-09-08 01:24:57 UTC (rev 8247)
+++ code/stage/trunk/libstage/model.cc 2009-09-08 01:38:21 UTC (rev 8248)
@@ -114,9 +114,22 @@
void Size::Load( Worldfile* wf, int section, const char* keyword )
{
- x = wf->ReadTupleLength( section, keyword, 0, x );
- y = wf->ReadTupleLength( section, keyword, 1, y );
- z = wf->ReadTupleLength( section, keyword, 2, z );
+ CProperty* prop = wf->GetProperty( section, keyword );
+
+ if( prop )
+ {
+ if( prop->value_count != 3 )
+ {
+ puts( "" ); // newline
+ PRINT_ERR1( "Loading size. Need a
vector of length 3: found %d.\n",
+
prop->value_count );
+ exit(-1);
+ }
+
+ x = atof( wf->GetPropertyValue( prop, 0 )) *
wf->unit_length;
+ y = atof( wf->GetPropertyValue( prop, 1 )) *
wf->unit_length;
+ z = atof( wf->GetPropertyValue( prop, 2 )) *
wf->unit_length;
+ }
}
void Size::Save( Worldfile* wf, int section, const char* keyword )
@@ -128,10 +141,23 @@
void Pose::Load( Worldfile* wf, int section, const char* keyword )
{
- x = wf->ReadTupleLength( section, keyword, 0, x );
- y = wf->ReadTupleLength( section, keyword, 1, y );
- z = wf->ReadTupleLength( section, keyword, 2, z );
- a = wf->ReadTupleAngle( section, keyword, 3, a );
+ CProperty* prop = wf->GetProperty( section, keyword );
+
+ if( prop )
+ {
+ if( prop->value_count != 4 )
+ {
+ puts( "" ); // newline
+ PRINT_ERR1( "Loading pose. Need a
vector of length 4: found %d.\n",
+
prop->value_count );
+ exit(-1);
+ }
+
+ x = atof( wf->GetPropertyValue( prop, 0 )) *
wf->unit_length;
+ y = atof( wf->GetPropertyValue( prop, 1 )) *
wf->unit_length;
+ z = atof( wf->GetPropertyValue( prop, 2 )) *
wf->unit_length;
+ a = atof( wf->GetPropertyValue( prop, 3 )) *
wf->unit_angle;
+ }
}
void Pose::Save( Worldfile* wf, int section, const char* keyword )
Modified: code/stage/trunk/libstage/model_load.cc
===================================================================
--- code/stage/trunk/libstage/model_load.cc 2009-09-08 01:24:57 UTC (rev
8247)
+++ code/stage/trunk/libstage/model_load.cc 2009-09-08 01:38:21 UTC (rev
8248)
@@ -73,49 +73,49 @@
//PRINT_WARN1( "%s::Load", token );
- if( wf->PropertyExists( wf_entity, "origin" ) )
+ //if( wf->PropertyExists( wf_entity, "origin" ) )
{
Geom geom = GetGeom();
- geom.pose.Load( wf, wf_entity, "origin" );
+ geom.pose.Load( wf, wf_entity, "origin" );
SetGeom( geom );
}
-
- if( wf->PropertyExists( wf_entity, "size" ) )
+
+ //if( wf->PropertyExists( wf_entity, "size" ) )
{
Geom geom = GetGeom();
- geom.size.Load( wf, wf_entity, "size" );
+ geom.size.Load( wf, wf_entity, "size" );
SetGeom( geom );
}
-
- if( wf->PropertyExists( wf_entity, "pose" ))
+
+ //if( wf->PropertyExists( wf_entity, "pose" ))
{
Pose pose = GetPose();
- pose.Load( wf, wf_entity, "pose" );
+ pose.Load( wf, wf_entity, "pose" );
SetPose( pose );
}
-
- if( wf->PropertyExists( wf_entity, "velocity" ))
+
+ //if( wf->PropertyExists( wf_entity, "velocity" ))
{
Velocity vel = GetVelocity();
- vel.Load( wf, wf_entity, "velocity" );
+ vel.Load( wf, wf_entity, "velocity" );
SetVelocity( vel );
}
-
- if( wf->PropertyExists( wf_entity, "color" ))
- {
- Color col( 1,0,0 ); // red;
- const char* colorstr = wf->ReadString( wf_entity, "color", NULL );
- if( colorstr )
- {
- if( strcmp( colorstr, "random" ) == 0 )
- col = Color( drand48(), drand48(), drand48() );
- else
- col = Color( colorstr );
- }
- this->SetColor( col );
- }
+
+ if( wf->PropertyExists( wf_entity, "color" ))
+ {
+ Color col( 1,0,0 ); // red;
+ const char* colorstr = wf->ReadString(
wf_entity, "color", NULL );
+ if( colorstr )
+ {
+ if( strcmp( colorstr, "random"
) == 0 )
+ col = Color( drand48(),
drand48(), drand48() );
+ else
+ col = Color( colorstr );
+ }
+ this->SetColor( col );
+ }
+
-
if( wf->PropertyExists( wf_entity, "color_rgba" ))
{
if (wf->GetProperty(wf_entity,"color_rgba")->value_count < 4)
Modified: code/stage/trunk/libstage/worldfile.cc
===================================================================
--- code/stage/trunk/libstage/worldfile.cc 2009-09-08 01:24:57 UTC (rev
8247)
+++ code/stage/trunk/libstage/worldfile.cc 2009-09-08 01:38:21 UTC (rev
8248)
@@ -70,6 +70,7 @@
entity_size( 0),
entity_count( 0),
entities( NULL),
+ properties(NULL),
property_count( 0),
filename( NULL),
unit_length( 1.0),
@@ -240,16 +241,16 @@
// Check for unused properties and print warnings
bool Worldfile::WarnUnused()
{
- // bool unused = false;
- // for (int i = 0; i < this->property_count; i++)
+ // bool unused = false;
+ // for (int i = 0; i < this->property_count; i++)
// {
// CProperty *property = this->properties + i;
// if (!property->used)
- // {
- // unused = true;
- // PRINT_WARN3("worldfile %s:%d : property [%s] is defined but not
used",
- // this->filename, property->line, property->name);
- // }
+ // {
+ // unused = true;
+ // PRINT_WARN3("worldfile %s:%d : property
[%s] is defined but not used",
+ //
this->filename, property->line, property->name);
+ // }
// }
// return unused;
return false;
@@ -1376,18 +1377,16 @@
{
char key[128];
snprintf( key, 127, "%d%s", entity, name );
-
- // printf( "looking up key %s for entity %d name %s\n", key, entity, name );
-
- CProperty* prop = nametable[ key ];
-
-// if( prop )
-// printf( "found entity %d name %s\n", prop->entity, prop->name );
-// else
-// printf( "key %s not found\n", key );
- return prop;
-}
+ //printf( "looking up key %s for entity %d name %s\n", key, entity, name );
+
+ std::map<std::string,CProperty*>::iterator it = nametable.find( key );
+
+ if( it == nametable.end() ) // not found
+ return NULL;
+ else
+ return it->second;
+ }
bool Worldfile::PropertyExists( int section, const char* token )
Modified: code/stage/trunk/libstage/worldfile.hh
===================================================================
--- code/stage/trunk/libstage/worldfile.hh 2009-09-08 01:24:57 UTC (rev
8247)
+++ code/stage/trunk/libstage/worldfile.hh 2009-09-08 01:38:21 UTC (rev
8248)
@@ -271,7 +271,7 @@
private: void SetPropertyValue( CProperty* property, int index, const char
*value);
// Get the value of an property.
- private: const char *GetPropertyValue( CProperty* property, int index);
+ public: const char *GetPropertyValue( CProperty* property, int index);
// Dump the property list for debugging
private: void DumpProperties();
@@ -349,9 +349,9 @@
public: char *filename;
// Conversion units
- private: double unit_length;
- private: double unit_angle;
-
+ public: double unit_length;
+ public: double unit_angle;
+
private: std::map<std::string,CProperty*> nametable;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit