Revision: 8712
http://playerstage.svn.sourceforge.net/playerstage/?rev=8712&view=rev
Author: natepak
Date: 2010-05-25 17:31:59 +0000 (Tue, 25 May 2010)
Log Message:
-----------
Fixed memory leaks
Modified Paths:
--------------
code/gazebo/branches/simpar/server/XMLConfig.cc
code/gazebo/branches/simpar/server/XMLConfig.hh
code/gazebo/branches/simpar/server/physics/ode/ODEBoxShape.hh
code/gazebo/branches/simpar/worlds/coffee_cup.world
code/gazebo/branches/simpar/worlds/pendulum.world
code/gazebo/branches/simpar/worlds/pr2.world
code/gazebo/branches/simpar/worlds/simpleshapes.world
code/gazebo/branches/simpar/worlds/single_box.world
code/gazebo/branches/simpar/worlds/test_stacks.world
code/gazebo/branches/simpar/worlds/test_stacks_with_rays.world
code/gazebo/branches/simpar/worlds/trimesh.world
Modified: code/gazebo/branches/simpar/server/XMLConfig.cc
===================================================================
--- code/gazebo/branches/simpar/server/XMLConfig.cc 2010-05-25 01:37:27 UTC
(rev 8711)
+++ code/gazebo/branches/simpar/server/XMLConfig.cc 2010-05-25 17:31:59 UTC
(rev 8712)
@@ -35,6 +35,8 @@
#include <libxml/xinclude.h>
#include <libxml/xpointer.h>
+#include <boost/algorithm/string.hpp>
+
#include "GazeboError.hh"
#include "Global.hh"
#include "XMLConfig.hh"
@@ -426,10 +428,10 @@
////////////////////////////////////////////////////////////////////////////
// Get a value associated with a node.
-xmlChar* XMLConfigNode::GetNodeValue( const std::string &key ) const
+std::string XMLConfigNode::GetNodeValue( const std::string &key ) const
{
+ std::string result;
xmlChar *value=NULL;
- xmlChar *result=NULL;
// First check if the key is an attribute
if (xmlHasProp( this->xmlNode, (xmlChar*) key.c_str() ))
@@ -466,11 +468,9 @@
if (value)
{
- int j = xmlStrlen(value)-1;
- int i = 0;
- while (value[i] == ' ') i++;
- while (value[j] == ' ') j--;
- result = xmlStrndup(value+i, j-i+1);
+ result = (char*)value;
+ boost::trim(result);
+
xmlFree(value);
}
@@ -490,37 +490,31 @@
// Get a string value.
std::string XMLConfigNode::GetString( const std::string &key, const
std::string &def, int require) const
{
- xmlChar *value = this->GetNodeValue( key );
+ std::string value = this->GetNodeValue( key );
- if (!value && require)
+ if (value.empty() && require)
{
gzthrow( "unable to find required string attribute[" << key << "] in world
file node[" << this->GetName() << "]");
}
- else if ( !value )
+ else if ( value.empty() )
return def;
// TODO: cache the value somewhere (currently leaks)
- return (char *)value;
+ return value;
}
unsigned char XMLConfigNode::GetChar( const std::string &key, char def, int
require ) const
{
- unsigned char result = ' ';
+ std::string value = this->GetNodeValue( key );
- xmlChar *value = this->GetNodeValue( key );
-
- if (!value && require)
+ if (value.empty() && require)
{
gzthrow("unable to find required char attribute[" << key << "] in world
file node[" << this->GetName() << "]");
}
- else if ( !value )
+ else if ( value.empty() )
return def;
- result = value[0];
-
- xmlFree( value );
-
- return result;
+ return value[0];
}
///////////////////////////////////////////////////////////////////////////
@@ -587,16 +581,16 @@
// Get an integer
int XMLConfigNode::GetInt( const std::string &key, int def, int require ) const
{
- xmlChar *value = this->GetNodeValue( key );
+ std::string value = this->GetNodeValue( key );
- if (!value && require)
+ if (value.empty() && require)
{
gzthrow ("unable to find required int attribute[" << key << "] in world
file node[" << this->GetName() << "]");
}
- else if ( !value )
+ else if ( value.empty() )
return def;
- return atoi((const char*) value);
+ return boost::lexical_cast<int>(value);
}
@@ -604,32 +598,32 @@
// Get a double
double XMLConfigNode::GetDouble( const std::string &key, double def, int
require ) const
{
- xmlChar *value = this->GetNodeValue( key );
+ std::string value = this->GetNodeValue( key );
- if (!value && require)
+ if (value.empty() && require)
{
gzthrow( "unable to find required double attribute[" << key << "] in world
file node[" << this->GetName() << "]");
}
- else if ( !value )
+ else if ( value.empty() )
return def;
- return atof((const char*) value);
+ return boost::lexical_cast<double>(value);
}
////////////////////////////////////////////////////////////////////////////
// Get a float
float XMLConfigNode::GetFloat( const std::string &key, float def, int require
) const
{
- xmlChar *value = this->GetNodeValue( key );
+ std::string value = this->GetNodeValue( key );
- if (!value && require)
+ if (value.empty() && require)
{
gzthrow( "unable to find required float attribute[" << key << "] in world
file node[" << this->GetName() << "]");
}
- else if ( !value )
+ else if ( value.empty() )
return def;
- return (float)(atof((const char*) value));
+ return boost::lexical_cast<float>(value);
}
@@ -638,27 +632,22 @@
bool XMLConfigNode::GetBool( const std::string &key, bool def, int require )
const
{
bool result = false;
- xmlChar *value = this->GetNodeValue( key );
+ std::string value = this->GetNodeValue( key );
- if (!value && require)
+ if (value.empty() && require)
{
- xmlFree(value);
gzthrow( "unable to find required bool attribute[" << key << "] in world
file node[" << this->GetName() << "]");
}
- else if ( !value )
- {
- xmlFree(value);
+ else if ( value.empty() )
return def;
- }
- if (strcmp((const char*) value, "true") == 0)
+ if (value == "true")
result = true;
- else if (strcmp((const char*) value, "false") == 0)
+ else if (value == "false")
result = false;
else
- result = atoi((const char*) value);
+ result = boost::lexical_cast<bool>(value);
- xmlFree(value);
return result;
}
@@ -757,77 +746,17 @@
////////////////////////////////////////////////////////////////////////////
// Get a tuple string value.
std::string XMLConfigNode::GetTupleString( const std::string &key, int index,
- const std::string &def) const
+ const std::string &def) const
{
- xmlChar *value;
- std::string nvalue;
- int i, a, b, state, count;
+ std::vector<std::string> split_vector;
+ std::string value = this->GetNodeValue( key );
+ boost::trim(value);
+ boost::split(split_vector, value, boost::is_any_of(" "));
- value = this->GetNodeValue( key );
-
- if (value == NULL)
+ if (index < (int)split_vector.size())
+ return split_vector[index];
+ else
return def;
-
- state = 0;
- count = 0;
- a = b = 0;
-
- for (i = 0; i < (int) strlen((const char*) value); i++)
- {
- // Look for start of element
- if (state == 0)
- {
- if (!isspace( value[i] ))
- {
- a = i;
- state = 1;
- }
- }
-
- // Look for end of element
- else if (state == 1)
- {
- if (isspace( value[i] ))
- {
- state = 0;
- b = i - 1;
- count++;
- if (count > index)
- break;
- }
- }
- }
-
- if (state == 1)
- {
- b = i - 1;
- count++;
- }
-
- if (count == index + 1)
- {
- //nvalue = strndup( (const char*) value + a, b - a + 2 );
- const char *s = (const char*) value +a;
- size_t size = b-a+2;
- char *end = (char *)memchr(s,0,size);
-
- if (end)
- size = end -s + 1;
-
- char *r = (char *)malloc(size);
-
- if (size)
- {
- memcpy(r, s, size-1);
- r[size-1] = '\0';
- }
-
- nvalue = r;
- }
-
- xmlFree( value );
-
- return nvalue;
}
////////////////////////////////////////////////////////////////////////////
Modified: code/gazebo/branches/simpar/server/XMLConfig.hh
===================================================================
--- code/gazebo/branches/simpar/server/XMLConfig.hh 2010-05-25 01:37:27 UTC
(rev 8711)
+++ code/gazebo/branches/simpar/server/XMLConfig.hh 2010-05-25 17:31:59 UTC
(rev 8712)
@@ -198,7 +198,7 @@
//public: void SetValue(const std::string &key, const StringValue &data,
int require =0, int type=0);
/// \brief Get a node's value, which is either a attribute or child node
value.
- protected: xmlChar* GetNodeValue( const std::string &key ) const;
+ protected: std::string GetNodeValue( const std::string &key ) const;
/// \brief Set a node's value, either attribute or child node value
(private)
protected: bool SetNodeValue(const std::string& key,const std::string&
value);
Modified: code/gazebo/branches/simpar/server/physics/ode/ODEBoxShape.hh
===================================================================
--- code/gazebo/branches/simpar/server/physics/ode/ODEBoxShape.hh
2010-05-25 01:37:27 UTC (rev 8711)
+++ code/gazebo/branches/simpar/server/physics/ode/ODEBoxShape.hh
2010-05-25 17:31:59 UTC (rev 8712)
@@ -19,8 +19,9 @@
ODEGeom *oParent = (ODEGeom*)(this->parent);
Pose3d rpose;
+
dMass odeMass;
-
+
Mass mass = this->parent->GetMass();
// Initialize box mass matrix
Modified: code/gazebo/branches/simpar/worlds/coffee_cup.world
===================================================================
--- code/gazebo/branches/simpar/worlds/coffee_cup.world 2010-05-25 01:37:27 UTC
(rev 8711)
+++ code/gazebo/branches/simpar/worlds/coffee_cup.world 2010-05-25 17:31:59 UTC
(rev 8712)
@@ -21,7 +21,7 @@
<gravity>0 0 -9.80665</gravity>
<cfm>10e-8</cfm>
<erp>0.3</erp>
- <stepType>true</stepType>
+ <stepType>quick</stepType>
<stepIters>50</stepIters>
<stepW>1.3</stepW>
<contactMaxCorrectingVel>100.0</contactMaxCorrectingVel>
Modified: code/gazebo/branches/simpar/worlds/pendulum.world
===================================================================
--- code/gazebo/branches/simpar/worlds/pendulum.world 2010-05-25 01:37:27 UTC
(rev 8711)
+++ code/gazebo/branches/simpar/worlds/pendulum.world 2010-05-25 17:31:59 UTC
(rev 8712)
@@ -19,7 +19,7 @@
<gravity>0 0 -9.8</gravity>
<cfm>10e-10</cfm>
<erp>0.2</erp>
- <stepType>true</stepType>
+ <stepType>quick</stepType>
<stepIters>50</stepIters>
<stepW>1.3</stepW>
<contactMaxCorrectingVel>100.0</contactMaxCorrectingVel>
Modified: code/gazebo/branches/simpar/worlds/pr2.world
===================================================================
--- code/gazebo/branches/simpar/worlds/pr2.world 2010-05-25 01:37:27 UTC
(rev 8711)
+++ code/gazebo/branches/simpar/worlds/pr2.world 2010-05-25 17:31:59 UTC
(rev 8712)
@@ -21,7 +21,7 @@
<cfm>10e-10</cfm>
<erp>0.2</erp>
<updateRate>0</updateRate>
- <stepType>true</stepType>
+ <stepType>quick</stepType>
<stepIters>50</stepIters>
<stepW>1.3</stepW>
<contactMaxCorrectingVel>100.0</contactMaxCorrectingVel>
Modified: code/gazebo/branches/simpar/worlds/simpleshapes.world
===================================================================
--- code/gazebo/branches/simpar/worlds/simpleshapes.world 2010-05-25
01:37:27 UTC (rev 8711)
+++ code/gazebo/branches/simpar/worlds/simpleshapes.world 2010-05-25
17:31:59 UTC (rev 8712)
@@ -19,7 +19,7 @@
<gravity>0 0 -9.8</gravity>
<cfm>10e-10</cfm>
<erp>0.2</erp>
- <stepType>true</stepType>
+ <stepType>robust</stepType>
<stepIters>50</stepIters>
<stepW>1.3</stepW>
<contactMaxCorrectingVel>100.0</contactMaxCorrectingVel>
Modified: code/gazebo/branches/simpar/worlds/single_box.world
===================================================================
--- code/gazebo/branches/simpar/worlds/single_box.world 2010-05-25 01:37:27 UTC
(rev 8711)
+++ code/gazebo/branches/simpar/worlds/single_box.world 2010-05-25 17:31:59 UTC
(rev 8712)
@@ -19,7 +19,7 @@
<gravity>0 0 -9.8</gravity>
<cfm>10e-10</cfm>
<erp>0.2</erp>
- <stepType>true</stepType>
+ <stepType>quick</stepType>
<stepIters>50</stepIters>
<stepW>1.3</stepW>
<contactMaxCorrectingVel>100.0</contactMaxCorrectingVel>
Modified: code/gazebo/branches/simpar/worlds/test_stacks.world
===================================================================
--- code/gazebo/branches/simpar/worlds/test_stacks.world 2010-05-25
01:37:27 UTC (rev 8711)
+++ code/gazebo/branches/simpar/worlds/test_stacks.world 2010-05-25
17:31:59 UTC (rev 8712)
@@ -27,7 +27,7 @@
<gravity>0 0 -9.8</gravity>
<cfm>0.001</cfm>
<erp>0.1</erp>
- <stepType>true</stepType>
+ <stepType>quick</stepType>
<stepIters>30</stepIters>
<stepW>1.3</stepW>
</physics:ode>
Modified: code/gazebo/branches/simpar/worlds/test_stacks_with_rays.world
===================================================================
--- code/gazebo/branches/simpar/worlds/test_stacks_with_rays.world
2010-05-25 01:37:27 UTC (rev 8711)
+++ code/gazebo/branches/simpar/worlds/test_stacks_with_rays.world
2010-05-25 17:31:59 UTC (rev 8712)
@@ -27,7 +27,7 @@
<gravity>0 0 -9.8</gravity>
<cfm>0.0000000001</cfm>
<erp>0.2</erp>
- <stepType>true</stepType>
+ <stepType>quick</stepType>
<stepIters>10</stepIters>
<stepW>1.3</stepW>
</physics:ode>
Modified: code/gazebo/branches/simpar/worlds/trimesh.world
===================================================================
--- code/gazebo/branches/simpar/worlds/trimesh.world 2010-05-25 01:37:27 UTC
(rev 8711)
+++ code/gazebo/branches/simpar/worlds/trimesh.world 2010-05-25 17:31:59 UTC
(rev 8712)
@@ -21,7 +21,7 @@
<gravity>0 0 -9.80665</gravity>
<cfm>10e-8</cfm>
<erp>0.3</erp>
- <stepType>true</stepType>
+ <stepType>quick</stepType>
<stepIters>20</stepIters>
<stepW>1.3</stepW>
<contactMaxCorrectingVel>100.0</contactMaxCorrectingVel>
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