Skip to content

Commit

Permalink
Shared ptr yakkety (#207)
Browse files Browse the repository at this point in the history
* Ignore VIM swap files
* Forward declare urdf::Model when urdfdom version is > 0.4
* Add test for upcasting from urdf::ModelSharedPtr to urdf::ModelInterfaceSharedPtr
* Document info about urdfdom shared pointers
  • Loading branch information
sloretz authored Jun 27, 2017
1 parent 11f6d02 commit 5306845
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# VIM
.*.sw?
2 changes: 2 additions & 0 deletions urdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ if(CATKIN_ENABLE_TESTING)
find_package(catkin REQUIRED COMPONENTS rostest)
add_rostest_gtest(test_urdf_parser test/test_robot_model_parser.launch test/test_robot_model_parser.cpp)
target_link_libraries(test_urdf_parser ${PROJECT_NAME})

catkin_add_gtest(urdfdom_compatibility_test test/urdfdom_compatibility.cpp)
endif()

# no idea how CATKIN does this
Expand Down
53 changes: 53 additions & 0 deletions urdf/test/urdfdom_compatibility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2017 Open Source Robotics Foundation
* 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.
*********************************************************************/

#include <gtest/gtest.h>
#include "urdf/model.h"


TEST(UrdfCompatibility, UpcastSharedPtr)
{
urdf::ModelSharedPtr model(new urdf::Model);
model->name_ = "UpcastSharedPtr";
urdf::ModelInterfaceSharedPtr interface = model;
EXPECT_EQ(std::string("UpcastSharedPtr"), interface->getName());
}


int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

10 changes: 9 additions & 1 deletion urdf/urdfdom_compatibility.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
#define URDFDOM_HEADERS_MINOR_VERSION @URDFDOM_HEADERS_MINOR_VERSION@
#define URDFDOM_HEADERS_REVISION_VERSION @URDFDOM_HEADERS_REVISION_VERSION@

// for Wily: maintain compatibility between urdfdom 0.3 and 0.4 (definining SharedPtr types)
// Define shared pointers for urdfdom versions less than 0.4
// Plus define ModelSharedPtr for 0.4
#if URDFDOM_HEADERS_MAJOR_VERSION == 0 && URDFDOM_HEADERS_MINOR_VERSION <= 4

#include <boost/shared_ptr.hpp>
Expand All @@ -54,6 +55,8 @@ typedef boost::shared_ptr<const Class> Class##ConstSharedPtr; \
typedef boost::weak_ptr<Class> Class##WeakPtr

namespace urdf {
// These shared_ptrs were added to urdfdom in 0.4.0,
// so if urdfdom == 0.4 this is duplicate work
URDF_TYPEDEF_CLASS_POINTER(Box);
URDF_TYPEDEF_CLASS_POINTER(Collision);
URDF_TYPEDEF_CLASS_POINTER(Cylinder);
Expand All @@ -74,6 +77,8 @@ URDF_TYPEDEF_CLASS_POINTER(Sphere);
URDF_TYPEDEF_CLASS_POINTER(Visual);

URDF_TYPEDEF_CLASS_POINTER(ModelInterface);

// ModelSharedPtr is the only one that needs to be defined for urdfdom 0.4
URDF_TYPEDEF_CLASS_POINTER(Model);
}

Expand All @@ -89,6 +94,9 @@ typedef std::shared_ptr<ModelInterface> ModelInterfaceSharedPtr;
typedef std::shared_ptr<const ModelInterface> ModelInterfaceConstSharedPtr;
typedef std::weak_ptr<ModelInterface> ModelInterfaceWeakPtr;

// Forward declaration
class Model;

typedef std::shared_ptr<Model> ModelSharedPtr;
typedef std::shared_ptr<const Model> ModelConstSharedPtr;
typedef std::weak_ptr<Model> ModelWeakPtr;
Expand Down

0 comments on commit 5306845

Please sign in to comment.