Skip to content

Commit

Permalink
get rid of yamlcpp build dep
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Aug 28, 2020
1 parent f523a82 commit 98296b3
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 183 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ include(cmakemodules/script_triclops.cmake REQUIRED) # Check for PointGreyRes
include(cmakemodules/script_videre_svs.cmake REQUIRED) # Support for Videre Design stereo camera:
include(cmakemodules/script_wxwidgets.cmake REQUIRED) # Check for wxWidgets + GL
include(cmakemodules/script_xsens.cmake REQUIRED) # XSens Motion trackers / IMU drivers
include(cmakemodules/script_yamlcpp.cmake REQUIRED) # Check for YAMLCPP library
include(cmakemodules/script_zlib.cmake REQUIRED) # Check for zlib

# ---------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions apps/robotic-arm-kinematics/robotic-arm-kinematics.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,6 @@
<Unit filename="/home/jlblanco/code/mrpt/cmakemodules/script_nite2.cmake">
<Option virtualFolder="CMake Files\cmakemodules\" />
</Unit>
<Unit filename="/home/jlblanco/code/mrpt/cmakemodules/script_yamlcpp.cmake">
<Option virtualFolder="CMake Files\cmakemodules\" />
</Unit>
<Unit filename="/home/jlblanco/code/mrpt/cmakemodules/script_pcap.cmake">
<Option virtualFolder="CMake Files\cmakemodules\" />
</Unit>
Expand Down
4 changes: 1 addition & 3 deletions apps/rosbag2rawlog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


if(NOT (CMAKE_MRPT_HAS_YAMLCPP AND TARGET ros1bridge))
if(NOT TARGET ros1bridge)
return()
endif()

Expand All @@ -22,7 +21,6 @@ target_link_libraries(${PROJECT_NAME}
${rosbag_storage_LIBRARIES}
${cv_bridge_LIBRARIES}
${tf2_LIBRARIES}
${LIBYAMLCPP_LIBRARIES}
)

target_include_directories(${PROJECT_NAME}
Expand Down
1 change: 0 additions & 1 deletion cmakemodules/script_show_final_summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ SHOW_CONFIG_LINE_SYSTEM("PCAP (Wireshark logs for Velodyne) " CMAKE_MRPT_HAS_LI
SHOW_CONFIG_LINE_SYSTEM("SuiteSparse " CMAKE_MRPT_HAS_SUITESPARSE)
SHOW_CONFIG_LINE_SYSTEM("tinyxml2 " CMAKE_MRPT_HAS_TINYXML2)
SHOW_CONFIG_LINE_SYSTEM("wxWidgets " CMAKE_MRPT_HAS_WXWIDGETS "[Version: ${wxWidgets_VERSION_STRING} ${CMAKE_WXWIDGETS_TOOLKIT_NAME}]")
SHOW_CONFIG_LINE_SYSTEM("yamlcpp (YAML file format) " CMAKE_MRPT_HAS_YAMLCPP "[Version: ${LIBYAMLCPP_VERSION}]")
message(STATUS "")

message(STATUS " ______________________ GUI LIBRARIES ______________________")
Expand Down
31 changes: 0 additions & 31 deletions cmakemodules/script_yamlcpp.cmake

This file was deleted.

1 change: 0 additions & 1 deletion doc/CrossCompilingMRPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ cmake -S. -Bbuild-cross-arm \
-DCMAKE_TOOLCHAIN_FILE=doc/toolchain-gcc8-arm.cmake \
-DEIGEN_USE_EMBEDDED_VERSION=ON \
-DDISABLE_ASSIMP=ON \
-DDISABLE_YAMLCPP=ON \
-DDISABLE_ROS=ON \
-DDISABLE_WXWIDGETS=ON \
-DBUILD_APPLICATIONS=OFF \
Expand Down
3 changes: 1 addition & 2 deletions libs/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ define_mrpt_lib(
)

if(BUILD_mrpt-config)
target_link_libraries(config PRIVATE ${LIBYAMLCPP_LIBRARIES})
target_include_directories(config PRIVATE ${LIBYAMLCPP_INCLUDE_DIRS})

endif()
3 changes: 0 additions & 3 deletions libs/config/src/yaml2config_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
+------------------------------------------------------------------------+ */

#include <mrpt/config.h>
#if MRPT_HAS_YAMLCPP

#include <gtest/gtest.h>
#include <mrpt/config/CConfigFileMemory.h>
Expand Down Expand Up @@ -71,5 +70,3 @@ TEST(ini2yaml, parse)
// Note: we don't compare the exact strings since order of keys may vary (?)
EXPECT_EQ(sampleCfgTxt_as_yaml_correct.size(), c.getContentAsYAML().size());
}

#endif // MRPT_HAS_YAMLCPP
3 changes: 0 additions & 3 deletions libs/containers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ set_property(GLOBAL PROPERTY mrpt_containers_UNIT_TEST_EXTRA_DEPS mrpt-random mr

if(BUILD_mrpt-containers)

target_link_libraries(containers PRIVATE ${LIBYAMLCPP_LIBRARIES})
target_include_directories(containers PRIVATE ${LIBYAMLCPP_INCLUDE_DIRS})

if (TARGET mrpt_libfyaml)
target_link_libraries(containers PRIVATE mrpt_libfyaml)
endif()
Expand Down
114 changes: 105 additions & 9 deletions libs/containers/include/mrpt/containers/yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <array>
#include <cstdint>
#include <iosfwd>
#include <limits>
#include <map>
#include <optional>
#include <sstream>
Expand All @@ -31,8 +32,6 @@

// forward declarations
// clang-format off
// For YAMLCPP import:
namespace YAML { class Node; }
// For auxiliary proxies:
namespace mrpt::containers { class yaml;
namespace internal {
Expand Down Expand Up @@ -237,6 +236,19 @@ class yaml
*/
static yaml FromStream(std::istream& i);

/** Parses a text as YAML or JSON (autodetected) and stores the contents
* into this document.
*
* \exception std::exception Upon I/O or format errors
*/
void loadFromFile(const std::string& fileName);

/** Parses the filename as YAML or JSON (autodetected) and returns a
* document.
* \exception std::exception Upon I/O or format errors.
*/
static yaml FromFile(const std::string& fileName);

/** Parses the stream as YAML or JSON (autodetected) and stores the contents
* into this document.
*
Expand All @@ -245,12 +257,18 @@ class yaml
void loadFromStream(std::istream& i);

/** Builds an object copying the structure and contents from an existing
* YAMLCPP Node. Requires mrpt built against yamlcpp. */
static yaml FromYAMLCPP(const YAML::Node& n);
* YAMLCPP Node. Requires user to #include yamlcpp from your calling program
* (does NOT requires yamlcpp while compiling mrpt itself).
*
* \tparam YAML_NODE Must be `YAML::Node`. Made a template just to avoid
* build-time depedencies.
*/
template <typename YAML_NODE>
static yaml FromYAMLCPP(const YAML_NODE& n);

/** Imports the structure and contents from an existing
* YAMLCPP Node. Requires mrpt built against yamlcpp. */
void loadFromYAMLCPP(const YAML::Node& n);
/** \overload (loads an existing YAMLCPP into this) */
template <typename YAML_NODE>
void loadFromYAMLCPP(const YAML_NODE& n);

/** @} */

Expand All @@ -263,8 +281,8 @@ class yaml
* returns true for null(empty) nodes. */
bool empty() const;

/** For map or sequence nodes, clears all elements.
* \exception std::exception If called on a null or scalar node. */
/** Resets to empty (can be called on a root node or any other node to clear
* that subtree only). */
void clear();

bool isNullNode() const;
Expand Down Expand Up @@ -428,6 +446,7 @@ class yaml
{
return internal::implAsGetter<T>(*this);
}

/** Returns a ref to the existing or new value of the given type. If types
* do not match, the old content will be discarded and a new variable
* created into this scalar node.
Expand Down Expand Up @@ -695,6 +714,83 @@ void yaml::internalPushBack(const T& v)
seq.emplace_back().d.emplace<scalar_t>().emplace<T>(v);
}

template <typename YAML_NODE>
yaml yaml::FromYAMLCPP(const YAML_NODE& n)
{
const auto invalidDbl = std::numeric_limits<double>::max();

if (n.IsSequence())
{
yaml ret = yaml(Sequence());

for (const auto& e : n)
{
if (e.IsNull())
{
sequence_t& seq =
std::get<sequence_t>(ret.dereferenceProxy()->d);
seq.push_back(node_t());
}
else if (e.IsScalar())
{
if (double v = e.template as<double>(invalidDbl);
v != invalidDbl)
ret.push_back(v);
else
ret.push_back(e.template as<std::string>());
}
else
{
// Recursive:
ret.push_back(yaml::FromYAMLCPP(e));
}
}
return ret;
}
else if (n.IsMap())
{
yaml ret = yaml(yaml::Map());

for (const auto& kv : n)
{
const auto& key = kv.first.template as<std::string>();
const auto& val = kv.second;

if (val.IsNull())
{
map_t& m = std::get<map_t>(ret.dereferenceProxy()->d);
m[key];
}
else if (val.IsScalar())
{
if (double v = val.template as<double>(invalidDbl);
v != invalidDbl)
ret[key] = v;
else
ret[key] = val.template as<std::string>();
}
else
{
// Recursive:
ret[key] = yaml::FromYAMLCPP(val);
}
}
return ret;
}
else
{
THROW_EXCEPTION(
"FromYAMLCPP only supports root YAML as sequence "
"or map");
}
}

template <typename YAML_NODE>
void yaml::loadFromYAMLCPP(const YAML_NODE& n)
{
*this = yaml::FromYAMLCPP(n);
}

} // namespace mrpt::containers

namespace mrpt::containers::internal
Expand Down
Loading

0 comments on commit 98296b3

Please sign in to comment.