|
From: <is...@us...> - 2008-11-12 23:18:02
|
Revision: 6615
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=6615&view=rev
Author: isucan
Date: 2008-11-12 23:17:57 +0000 (Wed, 12 Nov 2008)
Log Message:
-----------
moved the code for dealing with resources to a separate package
Modified Paths:
--------------
pkg/trunk/robot_descriptions/wg_robot_description_parser/manifest.xml
pkg/trunk/robot_descriptions/wg_robot_description_parser/src/URDF.cpp
pkg/trunk/util/string_utils/include/string_utils/string_utils.h
Added Paths:
-----------
pkg/trunk/util/resource_locator/
pkg/trunk/util/resource_locator/.build-version
pkg/trunk/util/resource_locator/CMakeLists.txt
pkg/trunk/util/resource_locator/Makefile
pkg/trunk/util/resource_locator/include/
pkg/trunk/util/resource_locator/include/reslocator/
pkg/trunk/util/resource_locator/include/reslocator/reslocator.h
pkg/trunk/util/resource_locator/manifest.xml
pkg/trunk/util/resource_locator/src/
pkg/trunk/util/resource_locator/src/reslocator.cpp
Modified: pkg/trunk/robot_descriptions/wg_robot_description_parser/manifest.xml
===================================================================
--- pkg/trunk/robot_descriptions/wg_robot_description_parser/manifest.xml 2008-11-12 22:56:51 UTC (rev 6614)
+++ pkg/trunk/robot_descriptions/wg_robot_description_parser/manifest.xml 2008-11-12 23:17:57 UTC (rev 6615)
@@ -14,8 +14,6 @@
<depend package="string_utils"/>
<depend package="stl_utils" />
- <sysdepend os="ubuntu" version="8.04-hardy" package="libboost-regex-dev"/>
-
<export>
<cpp cflags="-I${prefix}/include" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lURDF"/>
</export>
Modified: pkg/trunk/robot_descriptions/wg_robot_description_parser/src/URDF.cpp
===================================================================
--- pkg/trunk/robot_descriptions/wg_robot_description_parser/src/URDF.cpp 2008-11-12 22:56:51 UTC (rev 6614)
+++ pkg/trunk/robot_descriptions/wg_robot_description_parser/src/URDF.cpp 2008-11-12 23:17:57 UTC (rev 6615)
@@ -42,8 +42,8 @@
#include <fstream>
#include <sstream>
#include <queue>
-#include <boost/regex.hpp>
+
namespace robot_desc {
/* Macro to mark the fact a certain member variable was set. Also
@@ -122,40 +122,7 @@
std::string URDF::getResourceLocation(void) const
{
- // check if URL is valid
- boost::cmatch matches;
- boost::regex re("(ros-pkg|ros-param):\\/\\/((\\w+\\.)*(\\w*))\\/([\\w\\d]+\\/{0,1})+");
- if (boost::regex_match(m_resourceLocation.c_str(), matches, re) && matches.size() >= 3) {
- std::string protocol(matches[1].first, matches[1].second);
- std::string protocol_path(matches[2].first, matches[2].second);
- std::string relpath(matches[2].second,matches[matches.size()-1].second);
-
- if( protocol == std::string("ros-pkg") ) {
- // find the ROS package
- FILE* f = popen((std::string("rospack find ") + protocol_path).c_str(),"r");
- if( f == NULL )
- errorMessage(std::string("failed to launch rospack find ") + protocol_path);
- else {
- char basepath[1024];
- fgets(basepath, sizeof(basepath), f);
- pclose(f);
-
- // strip out any new lines or spaces from the end
- int len = strlen(basepath);
- char* p = basepath+len-1;
- while(len-- > 0 && (*p == ' ' || *p == '\n' || *p == '\t' || *p == '\r'))
- *p-- = 0;
- return std::string(basepath) + relpath;
- }
- }
- else if( protocol == std::string("ros-param") ) {
- errorMessage("ros-param option for the media path is not supported");
- }
- }
- else // not a url so copy directly
- return m_resourceLocation;
-
- return "";
+ return m_resourceLocation;
}
URDF::Link* URDF::getLink(const std::string &name) const
Added: pkg/trunk/util/resource_locator/.build-version
===================================================================
--- pkg/trunk/util/resource_locator/.build-version (rev 0)
+++ pkg/trunk/util/resource_locator/.build-version 2008-11-12 23:17:57 UTC (rev 6615)
@@ -0,0 +1 @@
+:
Added: pkg/trunk/util/resource_locator/CMakeLists.txt
===================================================================
--- pkg/trunk/util/resource_locator/CMakeLists.txt (rev 0)
+++ pkg/trunk/util/resource_locator/CMakeLists.txt 2008-11-12 23:17:57 UTC (rev 6615)
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.6)
+include(rosbuild)
+rospack(resource_locator)
+rospack_add_library(resource_locator src/reslocator.cpp)
Added: pkg/trunk/util/resource_locator/Makefile
===================================================================
--- pkg/trunk/util/resource_locator/Makefile (rev 0)
+++ pkg/trunk/util/resource_locator/Makefile 2008-11-12 23:17:57 UTC (rev 6615)
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake.mk
Added: pkg/trunk/util/resource_locator/include/reslocator/reslocator.h
===================================================================
--- pkg/trunk/util/resource_locator/include/reslocator/reslocator.h (rev 0)
+++ pkg/trunk/util/resource_locator/include/reslocator/reslocator.h 2008-11-12 23:17:57 UTC (rev 6615)
@@ -0,0 +1,52 @@
+/*********************************************************************
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2008, Willow Garage, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of the Willow Garage nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *********************************************************************/
+
+/** \author Rosen Diankov, Ioan Sucan */
+
+#ifndef ROS_RESOURCE_LOCATOR_
+#define ROS_RESOURCE_LOCATOR_
+
+#include <string>
+
+namespace res_locator
+{
+
+ /** Attempt to compute the path equivalent to a resource. This is
+ * only valid for some types of resources. The function returns
+ * an empty string if unsuccesful */
+ std::string resource2path(const std::string &resource);
+
+}
+
+#endif
Added: pkg/trunk/util/resource_locator/manifest.xml
===================================================================
--- pkg/trunk/util/resource_locator/manifest.xml (rev 0)
+++ pkg/trunk/util/resource_locator/manifest.xml 2008-11-12 23:17:57 UTC (rev 6615)
@@ -0,0 +1,19 @@
+<package>
+ <description brief="Resource Locator">
+
+ This package provides a simple library that allows locating
+ resources within ROS.
+
+ </description>
+ <author>Rosen Diankov, Ioan Sucan </author>
+ <license>BSD</license>
+
+ <depend package="rosconsole" />
+
+ <export>
+ <cpp cflags="-I${prefix}/include" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lresource_locator"/>
+ </export>
+
+ <sysdepend os="ubuntu" version="8.04-hardy" package="libboost-regex-dev"/>
+
+</package>
Added: pkg/trunk/util/resource_locator/src/reslocator.cpp
===================================================================
--- pkg/trunk/util/resource_locator/src/reslocator.cpp (rev 0)
+++ pkg/trunk/util/resource_locator/src/reslocator.cpp 2008-11-12 23:17:57 UTC (rev 6615)
@@ -0,0 +1,80 @@
+/*********************************************************************
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2008, Willow Garage, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of the Willow Garage nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *********************************************************************/
+
+/** \author Rosen Diankov, Ioan Sucan */
+
+#include <reslocator/reslocator.h>
+#include <rosconsole/rosconsole.h>
+#include <boost/regex.hpp>
+
+
+std::string res_locator::resource2path(const std::string &resource)
+{
+ // check if URL is valid
+ boost::cmatch matches;
+ boost::regex re("(ros-pkg|ros-param):\\/\\/((\\w+\\.)*(\\w*))\\/([\\w\\d]+\\/{0,1})+");
+
+ if (boost::regex_match(resource.c_str(), matches, re) && matches.size() >= 3){
+ std::string protocol(matches[1].first, matches[1].second);
+ std::string protocol_path(matches[2].first, matches[2].second);
+ std::string relpath(matches[2].second,matches[matches.size()-1].second);
+
+ if( protocol == std::string("ros-pkg") ) {
+ // find the ROS package
+ FILE* f = popen((std::string("rospack find ") + protocol_path).c_str(),"r");
+ if( f == NULL )
+ ROS_ERROR("%s\n", (std::string("failed to launch rospack find ") + protocol_path).c_str());
+ else {
+ char basepath[1024];
+ fgets(basepath, sizeof(basepath), f);
+ pclose(f);
+
+ // strip out any new lines or spaces from the end
+ int len = strlen(basepath);
+ char* p = basepath+len-1;
+ while(len-- > 0 && (*p == ' ' || *p == '\n' || *p == '\t' || *p == '\r'))
+ *p-- = 0;
+ return std::string(basepath) + relpath;
+ }
+ }
+ else if( protocol == std::string("ros-param") )
+ {
+ return "";
+ }
+ }
+ else // not a url so copy directly
+ return resource;
+
+ return "";
+}
Modified: pkg/trunk/util/string_utils/include/string_utils/string_utils.h
===================================================================
--- pkg/trunk/util/string_utils/include/string_utils/string_utils.h 2008-11-12 22:56:51 UTC (rev 6614)
+++ pkg/trunk/util/string_utils/include/string_utils/string_utils.h 2008-11-12 23:17:57 UTC (rev 6615)
@@ -32,7 +32,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
-/** \Author Ioan Sucan */
+/** \author Ioan Sucan */
#ifndef STRING_UTILS_STRING_UTILS_
#define STRING_UTILS_STRING_UTILS_
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|