Revision: 6402
http://playerstage.svn.sourceforge.net/playerstage/?rev=6402&view=rev
Author: robotos
Date: 2008-05-08 05:15:41 -0700 (Thu, 08 May 2008)
Log Message:
-----------
Integrate patch 1946172, I've done a new private method to avoid copy/paste
Making a bunch of method const according to their true nature
Modified Paths:
--------------
code/gazebo/trunk/server/Simulator.cc
code/gazebo/trunk/server/Simulator.hh
code/gazebo/trunk/server/XMLConfig.cc
code/gazebo/trunk/server/XMLConfig.hh
Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc 2008-05-08 05:37:36 UTC (rev
6401)
+++ code/gazebo/trunk/server/Simulator.cc 2008-05-08 12:15:41 UTC (rev
6402)
@@ -247,7 +247,7 @@
////////////////////////////////////////////////////////////////////////////////
/// Gets our current GUI interface
-Gui *Simulator::GetUI()
+Gui *Simulator::GetUI() const
{
return this->gui;
}
@@ -262,7 +262,7 @@
////////////////////////////////////////////////////////////////////////////////
/// Get the number of iterations of this simulation session
-unsigned long Simulator::GetIterations()
+unsigned long Simulator::GetIterations() const
{
return this->iterations;
}
@@ -327,7 +327,7 @@
}
////////////////////////////////////////////////////////////////////////////////
-bool Simulator::GetUserPause()
+bool Simulator::GetUserPause() const
{
return userPause;
}
@@ -339,7 +339,7 @@
}
////////////////////////////////////////////////////////////////////////////////
-bool Simulator::GetUserStep()
+bool Simulator::GetUserStep() const
{
return userStep;
}
@@ -351,7 +351,7 @@
}
////////////////////////////////////////////////////////////////////////////////
-bool Simulator::GetUserStepInc()
+bool Simulator::GetUserStepInc() const
{
return userStepInc;
}
Modified: code/gazebo/trunk/server/Simulator.hh
===================================================================
--- code/gazebo/trunk/server/Simulator.hh 2008-05-08 05:37:36 UTC (rev
6401)
+++ code/gazebo/trunk/server/Simulator.hh 2008-05-08 12:15:41 UTC (rev
6402)
@@ -75,13 +75,13 @@
public: void MainLoop();
/// \brief Gets our current GUI interface
- public: Gui *GetUI();
+ public: Gui *GetUI() const;
/// \brief Returns the state of the simulation true if paused
public: bool IsPaused() const;
/// \brief Get the number of iterations
- public: unsigned long GetIterations();
+ public: unsigned long GetIterations() const;
/*
/// \brief Set the number of iterations
public: static void SetIterations(unsigned long count);
@@ -118,19 +118,19 @@
public: void SetUserQuit();
/// \brief Return true if the user has pased
- public: bool GetUserPause();
+ public: bool GetUserPause() const;
/// \brief Set whether the user has paused
public: void SetUserPause(bool pause);
/// \brief Return true if the user has stepped the simulation
- public: bool GetUserStep();
+ public: bool GetUserStep() const;
/// \brief Set whether the user has stepped the simulation
public: void SetUserStep( bool step );
/// \brief Return true if the step has incremented
- public: bool GetUserStepInc();
+ public: bool GetUserStepInc() const;
/// \brief Set whether the step has incremented
public: void SetUserStepInc(bool step);
Modified: code/gazebo/trunk/server/XMLConfig.cc
===================================================================
--- code/gazebo/trunk/server/XMLConfig.cc 2008-05-08 05:37:36 UTC (rev
6401)
+++ code/gazebo/trunk/server/XMLConfig.cc 2008-05-08 12:15:41 UTC (rev
6402)
@@ -72,31 +72,7 @@
// Load the file
this->xmlDoc = xmlParseFile( this->filename.c_str() );
- if (xmlDoc == NULL)
- {
- gzthrow( "Unable to parse xml file: " << this->filename);
- }
-
- // Create xpath evaluation context
- this->xpathContex = xmlXPathNewContext(this->xmlDoc);
- if (this->xpathContex == NULL)
- {
- gzthrow("Unable to create new XPath context");
- }
-
- // Apply the XInclude process.
- if (xmlXIncludeProcess(this->xmlDoc) < 0)
- {
- //this will fail if the included file is not found, too strict?
- gzthrow("XInclude process failed\n");
- }
-
- // Create wrappers for all the nodes (recursive)
- this->root = this->CreateNodes( NULL, xmlDocGetRootElement(this->xmlDoc) );
- if (this->root == NULL)
- {
- gzthrow( "Empty document [" << this->filename << "]");
- }
+ this->FillDocumentNodes();
}
void XMLConfig::LoadString( const std::string &str )
@@ -106,19 +82,7 @@
// Load the file
this->xmlDoc = xmlParseDoc( (xmlChar*)(str.c_str()) );
- if (xmlDoc == NULL)
- {
- gzthrow("unable to parse [" << str << "]");
- }
-
- // Create wrappers for all the nodes (recursive)
- this->root = this->CreateNodes( NULL,
- xmlDocGetRootElement(this->xmlDoc) );
-
- if (this->root == NULL)
- {
- gzthrow( "Empty document [" << str<< "]") ;
- }
+ this->FillDocumentNodes();
}
@@ -127,7 +91,7 @@
int XMLConfig::Save(const std::string &filename )
{
int result=0;
- if (filename==std::string())
+ if (filename == std::string())
result=xmlSaveFileEnc(this->filename.c_str(), this->xmlDoc, "UTF-8");
else
result=xmlSaveFileEnc(filename.c_str(), this->xmlDoc, "UTF-8");
@@ -143,7 +107,40 @@
}
+
////////////////////////////////////////////////////////////////////////////
+// Fills the document with information
+void XMLConfig::FillDocumentNodes()
+{
+ if (xmlDoc == NULL)
+ {
+ gzthrow( "Unable to parse xml file: " << this->filename);
+ }
+
+ // Create xpath evaluation context
+ this->xpathContex = xmlXPathNewContext(this->xmlDoc);
+ if (this->xpathContex == NULL)
+ {
+ gzthrow("Unable to create new XPath context");
+ }
+
+ // Apply the XInclude process.
+ if (xmlXIncludeProcess(this->xmlDoc) < 0)
+ {
+ //this will fail if the included file is not found, too strict?
+ gzthrow("XInclude process failed\n");
+ }
+
+ // Create wrappers for all the nodes (recursive)
+ this->root = this->CreateNodes( NULL, xmlDocGetRootElement(this->xmlDoc) );
+ if (this->root == NULL)
+ {
+ gzthrow( "Empty document [" << this->filename << "]");
+ }
+}
+
+
+////////////////////////////////////////////////////////////////////////////
// Create wrappers
XMLConfigNode *XMLConfig::CreateNodes( XMLConfigNode *parent,
xmlNodePtr xmlNode )
@@ -279,20 +276,19 @@
this->parent->childLast = this->prev;
}
- return;
}
////////////////////////////////////////////////////////////////////////////
// Get the node name
-std::string XMLConfigNode::GetName()
+std::string XMLConfigNode::GetName() const
{
return (const char*)(this->xmlNode->name);
}
////////////////////////////////////////////////////////////////////////////
// Get the Name Space Prefix
-std::string XMLConfigNode::GetNSPrefix()
+std::string XMLConfigNode::GetNSPrefix() const
{
if ( !this->xmlNode->ns )
return "";
@@ -302,14 +298,14 @@
////////////////////////////////////////////////////////////////////////////
// Get the next sibling of this node
-XMLConfigNode *XMLConfigNode::GetNext()
+XMLConfigNode *XMLConfigNode::GetNext() const
{
return this->next;
}
////////////////////////////////////////////////////////////////////////////
// Get the next sibling of this node
-XMLConfigNode *XMLConfigNode::GetNext(const std::string &name, const
std::string &prefix)
+XMLConfigNode *XMLConfigNode::GetNext(const std::string &name, const
std::string &prefix) const
{
XMLConfigNode *tmp;
@@ -325,7 +321,7 @@
////////////////////////////////////////////////////////////////////////////
// Get the next sibling of this node according the namespace prefix
-XMLConfigNode *XMLConfigNode::GetNextByNSPrefix(const std::string &prefix)
+XMLConfigNode *XMLConfigNode::GetNextByNSPrefix(const std::string &prefix)
const
{
XMLConfigNode *tmp;
@@ -341,14 +337,14 @@
////////////////////////////////////////////////////////////////////////////
// Get the first child of this node
-XMLConfigNode *XMLConfigNode::GetChild()
+XMLConfigNode *XMLConfigNode::GetChild() const
{
return this->childFirst;
}
////////////////////////////////////////////////////////////////////////////
// Get the first child with the appropriate NS prefix
-XMLConfigNode *XMLConfigNode::GetChildByNSPrefix(const std::string &prefix )
+XMLConfigNode *XMLConfigNode::GetChildByNSPrefix(const std::string &prefix )
const
{
XMLConfigNode *tmp;
@@ -364,7 +360,7 @@
////////////////////////////////////////////////////////////////////////////
// Rewind the node pointer to the first siblind
-XMLConfigNode *XMLConfigNode::Rewind()
+XMLConfigNode *XMLConfigNode::Rewind()
{
XMLConfigNode *result = this;
@@ -378,7 +374,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a child based on a name. Returns null if not found
-XMLConfigNode *XMLConfigNode::GetChild( const std::string &name, const
std::string &prefix )
+XMLConfigNode *XMLConfigNode::GetChild( const std::string &name, const
std::string &prefix ) const
{
XMLConfigNode *tmp;
for (tmp = this->childFirst; tmp != NULL; tmp = tmp->GetNext() )
@@ -417,7 +413,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a value associated with a node.
-xmlChar* XMLConfigNode::GetNodeValue( const std::string &key )
+xmlChar* XMLConfigNode::GetNodeValue( const std::string &key ) const
{
xmlChar *value=NULL;
@@ -460,7 +456,7 @@
////////////////////////////////////////////////////////////////////////////
// Get the value of this node
-std::string XMLConfigNode::GetValue()
+std::string XMLConfigNode::GetValue() const
{
return (const char*)xmlNodeListGetString(this->xmlDoc,
this->xmlNode->xmlChildrenNode, 1);
}
@@ -468,7 +464,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a string value.
-std::string XMLConfigNode::GetString( const std::string &key, const
std::string &def, int require)
+std::string XMLConfigNode::GetString( const std::string &key, const
std::string &def, int require) const
{
xmlChar *value = this->GetNodeValue( key );
@@ -483,7 +479,7 @@
return (char *)value;
}
-unsigned char XMLConfigNode::GetChar( const std::string &key, char def, int
require )
+unsigned char XMLConfigNode::GetChar( const std::string &key, char def, int
require ) const
{
unsigned char result = ' ';
@@ -506,7 +502,7 @@
///////////////////////////////////////////////////////////////////////////
// Get a file name. Always returns an absolute path. If the filename
// is entered as a relative path, we prepend the world file path.
-std::string XMLConfigNode::GetFilename( const std::string &key, const
std::string &def, int require)
+std::string XMLConfigNode::GetFilename( const std::string &key, const
std::string &def, int require) const
{
std::string filename = this->GetString( key, def, require );
@@ -535,7 +531,7 @@
////////////////////////////////////////////////////////////////////////////
// Get an integer
-int XMLConfigNode::GetInt( const std::string &key, int def, int require )
+int XMLConfigNode::GetInt( const std::string &key, int def, int require ) const
{
xmlChar *value = this->GetNodeValue( key );
@@ -552,7 +548,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a double
-double XMLConfigNode::GetDouble( const std::string &key, double def, int
require )
+double XMLConfigNode::GetDouble( const std::string &key, double def, int
require ) const
{
xmlChar *value = this->GetNodeValue( key );
@@ -568,7 +564,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a float
-float XMLConfigNode::GetFloat( const std::string &key, float def, int require )
+float XMLConfigNode::GetFloat( const std::string &key, float def, int require
) const
{
xmlChar *value = this->GetNodeValue( key );
@@ -585,7 +581,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a boolean
-bool XMLConfigNode::GetBool( const std::string &key, bool def, int require )
+bool XMLConfigNode::GetBool( const std::string &key, bool def, int require )
const
{
bool result = false;
xmlChar *value = this->GetNodeValue( key );
@@ -615,7 +611,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a length
-double XMLConfigNode::GetLength( const std::string &key, double def, int
require )
+double XMLConfigNode::GetLength( const std::string &key, double def, int
require ) const
{
double length = this->GetDouble(key, def, require);
@@ -627,7 +623,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a time
-gazebo::Time XMLConfigNode::GetTime( const std::string &key, double def, int
require )
+gazebo::Time XMLConfigNode::GetTime( const std::string &key, double def, int
require ) const
{
gazebo::Time time(this->GetDouble(key, def, require));
return time;
@@ -635,7 +631,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a position
-Vector3 XMLConfigNode::GetVector3( const std::string &key, Vector3 def )
+Vector3 XMLConfigNode::GetVector3( const std::string &key, Vector3 def ) const
{
Vector3 v;
@@ -651,7 +647,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a two dimensional double vector
-Vector2<double> XMLConfigNode::GetVector2d( const std::string &key,
Vector2<double> def )
+Vector2<double> XMLConfigNode::GetVector2d( const std::string &key,
Vector2<double> def ) const
{
Vector2<double> v;
@@ -666,7 +662,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a two dimensional int vector
-Vector2<int> XMLConfigNode::GetVector2i( const std::string &key, Vector2<int>
def )
+Vector2<int> XMLConfigNode::GetVector2i( const std::string &key, Vector2<int>
def ) const
{
Vector2<int> v;
@@ -682,7 +678,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a rotation
-Quatern XMLConfigNode::GetRotation( const std::string &key, Quatern def )
+Quatern XMLConfigNode::GetRotation( const std::string &key, Quatern def ) const
{
Quatern q;
Vector3 p;
@@ -707,7 +703,7 @@
////////////////////////////////////////////////////////////////////////////
// Get a tuple string value.
std::string XMLConfigNode::GetTupleString( const std::string &key, int index,
- const std::string &def)
+ const std::string &def) const
{
xmlChar *value;
std::string nvalue;
@@ -782,7 +778,7 @@
////////////////////////////////////////////////////////////////////////////
// Get an attribute tuple double value
-int XMLConfigNode::GetTupleInt( const std::string &key, int index, int def )
+int XMLConfigNode::GetTupleInt( const std::string &key, int index, int def )
const
{
std::string svalue;
@@ -796,7 +792,7 @@
////////////////////////////////////////////////////////////////////////////
// Get an attribute tuple double value
-double XMLConfigNode::GetTupleDouble( const std::string &key, int index,
double def )
+double XMLConfigNode::GetTupleDouble( const std::string &key, int index,
double def ) const
{
std::string svalue;
@@ -810,7 +806,7 @@
////////////////////////////////////////////////////////////////////////////
// Get an tuple length value (return value in meters)
-double XMLConfigNode::GetTupleLength( const std::string &key, int index,
double def )
+double XMLConfigNode::GetTupleLength( const std::string &key, int index,
double def ) const
{
std::string svalue;
@@ -826,7 +822,7 @@
////////////////////////////////////////////////////////////////////////////
// Get an tuple angle value (return value in radians)
-double XMLConfigNode::GetTupleAngle( const std::string &key, int index, double
def )
+double XMLConfigNode::GetTupleAngle( const std::string &key, int index, double
def ) const
{
std::string svalue;
@@ -840,7 +836,7 @@
////////////////////////////////////////////////////////////////////////////
// Set the value associated with a node.
-void XMLConfigNode::SetValue(const std::string &key, const StringValue &data,
int require, int type)
+void XMLConfigNode::SetValue(const std::string &key, const StringValue &data,
int require, int type)
{
bool success;
@@ -917,3 +913,5 @@
}
}
+
+
Modified: code/gazebo/trunk/server/XMLConfig.hh
===================================================================
--- code/gazebo/trunk/server/XMLConfig.hh 2008-05-08 05:37:36 UTC (rev
6401)
+++ code/gazebo/trunk/server/XMLConfig.hh 2008-05-08 12:15:41 UTC (rev
6402)
@@ -68,7 +68,10 @@
/// \brief Get the root node
public: XMLConfigNode *GetRootNode() const;
-
+
+ /// \brief Fill the document with information
+ private: void FillDocumentNodes();
+
/// \brief Create wrappers
private: XMLConfigNode *CreateNodes( XMLConfigNode *parent,
xmlNodePtr xmlNode );
@@ -96,28 +99,28 @@
public: ~XMLConfigNode();
/// \brief Get the node name
- public: std::string GetName();
+ public: std::string GetName() const;
/// \brief Get the name space prefix
- public: std::string GetNSPrefix();
+ public: std::string GetNSPrefix() const;
/// \brief Get the next sibling of this node
- public: XMLConfigNode *GetNext();
+ public: XMLConfigNode *GetNext() const;
/// \brief Get next by name
- public: XMLConfigNode *GetNext(const std::string &name,const std::string
&prefix=std::string());
+ public: XMLConfigNode *GetNext(const std::string &name,const std::string
&prefix=std::string()) const;
/// \brief Get next node by namespace prefix
- public: XMLConfigNode *GetNextByNSPrefix(const std::string &prefix);
+ public: XMLConfigNode *GetNextByNSPrefix(const std::string &prefix) const;
/// \brief Get the first child of this node
- public: XMLConfigNode *GetChild();
+ public: XMLConfigNode *GetChild() const;
/// \brief Get a child based on a name. Returns null if not found
- public: XMLConfigNode *GetChild(const std::string &name, const std::string
&prefix=std::string() );
+ public: XMLConfigNode *GetChild(const std::string &name, const std::string
&prefix=std::string() ) const;
/// \brief Get the first child with the specified namespace prefix
- public: XMLConfigNode *GetChildByNSPrefix(const std::string &prefix );
+ public: XMLConfigNode *GetChildByNSPrefix(const std::string &prefix )
const;
/// \brief Move child pointer back to beginning
public: XMLConfigNode *Rewind();
@@ -126,66 +129,66 @@
public: void Print();
/// \brief Return the value of the current node
- public: std::string GetValue();
+ public: std::string GetValue() const;
/// \brief Get an attribute string value
public: std::string GetString( const std::string &key, const std::string
&def,
- int require = 0 );
+ int require = 0 ) const;
/// \brief Get a attribute character value
- public: unsigned char GetChar( const std::string &key, char def, int
require = 0 );
+ public: unsigned char GetChar( const std::string &key, char def, int
require = 0 ) const;
/// \brief Get a file name. Always returns an absolute path.
/// If the filename is entered as a relative path, we prepend the
/// world file path.
public: std::string GetFilename( const std::string &key, const std::string
&def,
- int require = 0);
+ int require = 0) const;
/// \brief Get an integer
- public: int GetInt( const std::string &key, int def, int require = 0 );
+ public: int GetInt( const std::string &key, int def, int require = 0 )
const;
/// \brief Get a double
- public: double GetDouble( const std::string &key, double def, int require
= 0 );
+ public: double GetDouble( const std::string &key, double def, int require
= 0 ) const;
/// \brief Get a float
- public: float GetFloat( const std::string &key, float def, int require = 0
);
+ public: float GetFloat( const std::string &key, float def, int require = 0
) const;
/// \brief Get a boolean
- public: bool GetBool( const std::string &key, bool def, int require = 0 );
+ public: bool GetBool( const std::string &key, bool def, int require = 0 )
const;
/// \brief Get an attribute length value (return value in meters)
- public: double GetLength( const std::string &key, double def, int require
= 0 );
+ public: double GetLength( const std::string &key, double def, int require
= 0 ) const;
/// \brief Get an attribute time value (return value in seconds)
- public: gazebo::Time GetTime( const std::string &key, double def, int
require = 0 );
+ public: gazebo::Time GetTime( const std::string &key, double def, int
require = 0 ) const;
/// \brief Get a position
- public: Vector3 GetVector3( const std::string &key, Vector3 def );
+ public: Vector3 GetVector3( const std::string &key, Vector3 def ) const;
/// \brief Get a two dimensional double vector
- public: Vector2<double> GetVector2d( const std::string &key,
Vector2<double> def );
+ public: Vector2<double> GetVector2d( const std::string &key,
Vector2<double> def ) const;
/// \brief Get a two dimensional int vector
- public: Vector2<int> GetVector2i( const std::string &key, Vector2<int> def
);
+ public: Vector2<int> GetVector2i( const std::string &key, Vector2<int> def
) const;
/// \brief Get a rotation
- public: Quatern GetRotation( const std::string &key, Quatern def );
+ public: Quatern GetRotation( const std::string &key, Quatern def ) const;
/// \brief Get an attribute tuple value
public: std::string GetTupleString( const std::string &key, int index,
- const std::string &def );
+ const std::string &def ) const;
/// \brief Get an attribute tuple int value
- public: int GetTupleInt( const std::string &key, int index, int def );
+ public: int GetTupleInt( const std::string &key, int index, int def )
const;
/// \brief Get an attribute tuple double value
- public: double GetTupleDouble( const std::string &key, int index, double
def );
+ public: double GetTupleDouble( const std::string &key, int index, double
def ) const;
/// \brief Get an attribute tuple length value (return value in meters)
- public: double GetTupleLength( const std::string &key, int index, double
def );
+ public: double GetTupleLength( const std::string &key, int index, double
def ) const;
/// \brief Get an attribute tuple angle value (return value in radians)
- public: double GetTupleAngle( const std::string &key, int index, double
def );
+ public: double GetTupleAngle( const std::string &key, int index, double
def ) const;
/// \brief Set a node's value, either attribute or child node value, maybe
create it
/// \param key : the name of the element or attribute to write
@@ -195,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 );
+ protected: xmlChar* 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);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit