Skip to content

Commit

Permalink
Use find_package for msgpack
Browse files Browse the repository at this point in the history
  • Loading branch information
asherikov committed Nov 22, 2023
1 parent 1a3c470 commit 98d17da
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 91 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Added
-----
* Writers now take `allow_missing_entries_` parameter into account, omitting
'missing' entries, e.g., null pointers.
* Searching for `find_package()` with yaml-cpp.
* Searching for `yaml-cpp` and `msgpack` with `find_package()`.
* `ARILES_CPP_STANDARD` cmake flag.
* `ariles::write::Parameters`: +`allow_missing_entries_`
* `OptionalPointer` wrapper class for pointers that can be NULL if entry is missing.
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APT_INSTALL?=env DEBIAN_FRONTEND=noninteractive apt --yes --no-install-recommends install
MAKE_FLAGS?=-j7
MAKE_FLAGS?=-j14


CMAKE_DIR=./cmake/
Expand Down Expand Up @@ -141,8 +141,8 @@ test-ros: clean


test-noros: clean
${MAKE} build-tests TC=${TC} TYPE=Debug OPTIONS=cpp11_on_noros TARGETS="${TARGETS}" EXTRA_CMAKE_PARAM="${EXTRA_CMAKE_PARAM}"
${MAKE} clangcheck SCANBUILD=scan-build11 OPTIONS=cpp11_on_noros_tidy
${MAKE} build-tests TC=${TC} TYPE=Debug OPTIONS=noros TARGETS="${TARGETS}" EXTRA_CMAKE_PARAM="${EXTRA_CMAKE_PARAM}"
${MAKE} clangcheck SCANBUILD=scan-build15 OPTIONS=noros_tidy
${MAKE} cppcheck
${MAKE} spell

Expand Down Expand Up @@ -209,7 +209,7 @@ install-deps:


format:
${FIND_ARILES_SOURCES} | grep -v "better_enum.h" | xargs clang-format-12 -verbose -i
${FIND_ARILES_SOURCES} | grep -v "better_enum.h" | xargs clang-format15 -verbose -i

cppcheck:
# --inconclusive
Expand All @@ -231,6 +231,7 @@ cppcheck:
--suppress=unknownMacro \
--suppress=constStatement \
--suppress=unsignedLessThanZero \
--suppress=duplInheritedMember \
-i build \
-i tests/api_v2/regression_test_230.cpp \
3>&1 1>&2 2>&3 | tee cppcheck.err
Expand Down
9 changes: 7 additions & 2 deletions cmake/cmakeut_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function(cmakeut_compiler_flags STANDARD)


if (CMAKEUT_CLANG_TIDY)
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy clang-tidy-12 clang-tidy-14 REQUIRED)
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy clang-tidy-12 clang-tidy-14 clang-tidy15 REQUIRED)

set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE};-warnings-as-errors=*;-checks=*")

Expand All @@ -74,7 +74,7 @@ function(cmakeut_compiler_flags STANDARD)
# member variables can be public/protected
set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY},-cppcoreguidelines-non-private-member-variables-in-classes,-misc-non-private-member-variables-in-classes")
# member initialization in constructors -- false positives
set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY},-cppcoreguidelines-pro-type-member-init,-hicpp-member-init")
set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY},-cppcoreguidelines-pro-type-member-init,-hicpp-member-init,-cppcoreguidelines-prefer-member-initializer")
# default member initialization scatters initializations -- initialization must be done via constructors
set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY},-modernize-use-default-member-init")
# calling virtual functions from desctructors is well defined and generally safe
Expand All @@ -100,6 +100,11 @@ function(cmakeut_compiler_flags STANDARD)
# llvmlibc stuff
set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY},-llvmlibc-*")

# noisy
set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY},-altera-unroll-loops,-altera-id-dependent-backward-branch,-readability-identifier-length")
# false positives?
set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY},-bugprone-exception-escape,-clang-analyzer-cplusplus.NewDelete")

set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY},${CMAKEUT_CLANG_TIDY_EXTRA_IGNORES}")

# might be useful too
Expand Down
2 changes: 1 addition & 1 deletion extra_visitors/jsonnet/src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace ariles2

Reader::Reader()
{
preprocessor_ = JsonnetPreprocessorPtr(new JsonnetPreprocessor());
preprocessor_ = std::make_shared<JsonnetPreprocessor>();
preprocessor_->vm_ = static_cast<struct JsonnetVm *>(::jsonnet_make());
ARILES2_ASSERT(NULL != preprocessor_->vm_, "Could not initialize jsonnet preprocessor.");
}
Expand Down
28 changes: 17 additions & 11 deletions extra_visitors/msgpack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
set (TGT_ARILES_VISITOR_LIB "${PROJECT_NAME}_visitor_${ARILES_VISITOR}")

if(NOT ARILES_DEB_TARGETS)
find_library("ARILES_VISITOR_${ARILES_VISITOR}_LIBS" NAMES ${ARILES_VISITOR})
find_path("ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES" NAMES msgpack.hpp)
find_package(msgpack-cxx)

if (NOT ARILES_VISITOR_${ARILES_VISITOR}_LIBS OR NOT ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES)
pkg_search_module(${ARILES_VISITOR} msgpack)
if (msgpack-cxx_FOUND)
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "msgpack-cxx")
else()
find_library("ARILES_VISITOR_${ARILES_VISITOR}_LIBS" NAMES ${ARILES_VISITOR})
find_path("ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES" NAMES msgpack.hpp)

if (${ARILES_VISITOR}_FOUND)
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBRARY_DIRS "${${ARILES_VISITOR}_LIBRARY_DIRS}")
set(ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES "${${ARILES_VISITOR}_INCLUDE_DIRS}")
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "${${ARILES_VISITOR}_LIBRARIES}")
if (NOT ARILES_VISITOR_${ARILES_VISITOR}_LIBS OR NOT ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES)
pkg_search_module(${ARILES_VISITOR} msgpack)

link_directories(${ARILES_VISITOR_${ARILES_VISITOR}_LIBRARY_DIRS})
else()
message(FATAL_ERROR "${ARILES_VISITOR} is not found.")
if (${ARILES_VISITOR}_FOUND)
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBRARY_DIRS "${${ARILES_VISITOR}_LIBRARY_DIRS}")
set(ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES "${${ARILES_VISITOR}_INCLUDE_DIRS}")
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "${${ARILES_VISITOR}_LIBRARIES}")

link_directories(${ARILES_VISITOR_${ARILES_VISITOR}_LIBRARY_DIRS})
else()
message(FATAL_ERROR "${ARILES_VISITOR} is not found.")
endif()
endif()
endif()
endif()
Expand Down
4 changes: 2 additions & 2 deletions extra_visitors/msgpack/src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ namespace ariles2

while (buffer_offset != buffer_.size())
{
handles_.push_back(std::shared_ptr<::msgpack::object_handle>(new ::msgpack::object_handle));
handles_.push_back(std::make_shared<::msgpack::object_handle>());

unpack(*handles_[handles_.size() - 1], buffer_.data(), buffer_.size(), buffer_offset);
unpack(*handles_.back(), buffer_.data(), buffer_.size(), buffer_offset);
}
}
catch (const std::exception &e)
Expand Down
2 changes: 1 addition & 1 deletion extra_visitors/msgpack/src/reader_compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace ariles2

std::size_t Reader::startArray()
{
std::size_t size = impl_->getRawNode().via.array.size;
const std::size_t size = impl_->getRawNode().via.array.size;
impl_->node_stack_.emplace_back(0, size);

return (size);
Expand Down
13 changes: 6 additions & 7 deletions extra_visitors/msgpack/src/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ namespace ariles2
using PackerPtr = std::shared_ptr<::msgpack::packer<std::ostream>>;


private:
Writer(const Writer &);
void operator=(const Writer &);


public:
/// output file stream
std::ofstream config_ofs_;
Expand All @@ -45,11 +40,15 @@ namespace ariles2


public:
Writer(const Writer &) = delete;
void operator=(const Writer &) = delete;


explicit Writer(const std::string &file_name)
{
ariles2::write::Visitor::openFile(config_ofs_, file_name);
output_stream_ = &config_ofs_;
packer_ = PackerPtr(new ::msgpack::packer<std::ostream>(*output_stream_));
packer_ = std::make_shared<::msgpack::packer<std::ostream>>(*output_stream_);

nameless_counter_ = 0;
}
Expand All @@ -58,7 +57,7 @@ namespace ariles2
explicit Writer(std::ostream &output_stream)
{
output_stream_ = &output_stream;
packer_ = PackerPtr(new ::msgpack::packer<std::ostream>(*output_stream_));
packer_ = std::make_shared<::msgpack::packer<std::ostream>>(*output_stream_);

nameless_counter_ = 0;
}
Expand Down
13 changes: 6 additions & 7 deletions extra_visitors/msgpack/src/writer_compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ namespace ariles2
using PackerPtr = std::shared_ptr<::msgpack::packer<std::ostream>>;


private:
Writer(const Writer &);
void operator=(const Writer &);


public:
/// output file stream
std::ofstream config_ofs_;
Expand All @@ -41,18 +36,22 @@ namespace ariles2
PackerPtr packer_;

public:
Writer(const Writer &) = delete;
void operator=(const Writer &) = delete;


explicit Writer(const std::string &file_name)
{
ariles2::write::Visitor::openFile(config_ofs_, file_name);
output_stream_ = &config_ofs_;
packer_ = PackerPtr(new ::msgpack::packer<std::ostream>(*output_stream_));
packer_ = std::make_shared<::msgpack::packer<std::ostream>>(*output_stream_);
}


explicit Writer(std::ostream &output_stream)
{
output_stream_ = &output_stream;
packer_ = PackerPtr(new ::msgpack::packer<std::ostream>(*output_stream_));
packer_ = std::make_shared<::msgpack::packer<std::ostream>>(*output_stream_);
}
};
} // namespace impl
Expand Down
16 changes: 8 additions & 8 deletions extra_visitors/pugixml/src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ namespace ariles2
{
Reader::Reader(const std::string &file_name)
{
impl_ = ImplPtr(new impl::Reader());
impl_ = std::make_shared<impl::Reader>();

pugi::xml_parse_result result = impl_->document_.load_file(file_name.c_str(), pugi::parse_minimal);
const pugi::xml_parse_result result = impl_->document_.load_file(file_name.c_str(), pugi::parse_minimal);
ARILES2_ASSERT(result, std::string("Parsing of '") + file_name + "' failed: " + result.description());
impl_->node_stack_.push_back(impl_->document_); // NOLINT
}


Reader::Reader(std::istream &input_stream)
{
impl_ = ImplPtr(new impl::Reader());
impl_ = std::make_shared<impl::Reader>();

pugi::xml_parse_result result = impl_->document_.load(input_stream, pugi::parse_minimal);
const pugi::xml_parse_result result = impl_->document_.load(input_stream, pugi::parse_minimal);
ARILES2_ASSERT(result, std::string("Parsing failed: ") + result.description());
impl_->node_stack_.push_back(impl_->document_); // NOLINT
}
Expand All @@ -71,16 +71,16 @@ namespace ariles2

if (NULL != child)
{
impl_->node_stack_.push_back(child);
impl_->node_stack_.emplace_back(child);
return (true);
}

const pugi::xml_attribute attribute = impl_->getRawNode().attribute(child_name.c_str());
if (NULL != attribute)
{
pugi::xml_node new_child = impl_->getRawNode().append_child(child_name.c_str());
const pugi::xml_node new_child = impl_->getRawNode().append_child(child_name.c_str());
new_child.text() = attribute.value();
impl_->node_stack_.push_back(new_child);
impl_->node_stack_.emplace_back(new_child);
return (true);
}

Expand All @@ -99,7 +99,7 @@ namespace ariles2
const std::size_t /*min*/,
const std::size_t /*max*/)
{
pugi::xml_node child = impl_->getRawNode().first_child();
const pugi::xml_node child = impl_->getRawNode().first_child();
if (NULL != child)
{
impl_->node_stack_.emplace_back(child, NodeWrapper::ITERATED_MAP);
Expand Down
8 changes: 4 additions & 4 deletions extra_visitors/pugixml/src/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ namespace ariles2
{
Writer::Writer(const std::string &file_name)
{
impl_ = ImplPtr(new impl::Writer(file_name));
impl_ = std::make_shared<impl::Writer>(file_name);
}


Writer::Writer(std::ostream &output_stream)
{
impl_ = ImplPtr(new impl::Writer(output_stream));
impl_ = std::make_shared<impl::Writer>(output_stream);
}


Expand All @@ -89,7 +89,7 @@ namespace ariles2

void Writer::startMapEntry(const std::string &map_name)
{
impl_->node_stack_.push_back(impl_->getRawNode().append_child(map_name.c_str()));
impl_->node_stack_.emplace_back(impl_->getRawNode().append_child(map_name.c_str()));
}

void Writer::endMapEntry()
Expand All @@ -108,7 +108,7 @@ namespace ariles2
ARILES2_ASSERT(
impl_->node_stack_.back().index_ < impl_->node_stack_.back().size_,
"Internal error: namevalue.has more elements than expected.");
impl_->node_stack_.push_back(impl_->getRawNode().append_child("item"));
impl_->node_stack_.emplace_back(impl_->getRawNode().append_child("item"));
}

void Writer::endArrayElement()
Expand Down
6 changes: 5 additions & 1 deletion extra_visitors/yaml_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ if(NOT ARILES_DEB_TARGETS)

if(yaml-cpp_FOUND)
set(ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES "${YAML_CPP_INCLUDE_DIR}")
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "yaml-cpp")
if(TARGET yaml-cpp)
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "yaml-cpp")
else()
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "yaml-cpp::yaml-cpp")
endif()
else()
pkg_search_module(${ARILES_VISITOR} REQUIRED yaml-cpp>=0.5.1)

Expand Down
4 changes: 2 additions & 2 deletions extra_visitors/yaml_cpp/src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace ariles2
bool Reader::startMapEntry(const std::string &child_name)
{
ARILES2_TRACE_FUNCTION;
YAML::Node child = impl_->getRawNode()[child_name];
const YAML::Node child = impl_->getRawNode()[child_name];

if (not child.IsDefined() or child.IsNull())
{
Expand Down Expand Up @@ -156,7 +156,7 @@ namespace ariles2
ARILES2_TRACE_FUNCTION;
ARILES2_ASSERT(impl_->getRawNode().IsSequence(), "Entry is not an array.");

std::size_t size = impl_->getRawNode().size();
const std::size_t size = impl_->getRawNode().size();
impl_->node_stack_.emplace_back(0, size);

return (size);
Expand Down
18 changes: 9 additions & 9 deletions tests/api_v2/all_enabled_visitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@

// Do not have Reader and therefore are excluded from most of the tests
//
//#ifdef ARILES_VISITOR_octave
//#include <ariles2/visitors/octave.h>
//#endif
// #ifdef ARILES_VISITOR_octave
// #include <ariles2/visitors/octave.h>
// #endif
//
//#ifdef ARILES_VISITOR_namevalue
//#include <ariles2/visitors/namevalue.h>
//#endif
// #ifdef ARILES_VISITOR_namevalue
// #include <ariles2/visitors/namevalue.h>
// #endif
//
//#ifdef ARILES_VISITOR_graphviz
//#include <ariles2/visitors/namevalue.h>
//#endif
// #ifdef ARILES_VISITOR_graphviz
// #include <ariles2/visitors/namevalue.h>
// #endif
34 changes: 17 additions & 17 deletions tests/api_v2/regression_test_216.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@

int main()
{
ariles_tests::ConfigurableComplex a;
ariles_tests::ConfigurableComplexVerbose b;
ariles_tests::ConfigurableEmpty c;
ariles_tests::ConfigurableFinalize d;
ariles_tests::ConfigurableMember<int> e;
ariles_tests::ConfigurableBase f;
ariles_tests::ConfigurableDerived g;
ariles_tests::ConfigurableMinimal h;
ariles_tests::ConfigurableNoSetDefaults k;
ariles_tests::ConfigurablePointers l;
ariles_tests::ConfigurableAutoDeclare m;
ariles_tests::ConfigurableVerbose p;
ariles_tests::ConfigurableSpecialFloats q;
ariles_tests::ConfigurableStrictness1 r;
ariles_tests::ConfigurableStrictness2 s;
ariles_tests::ConfigurableAny t;
ariles_tests::ConfigurablePointersScalar u;
const ariles_tests::ConfigurableComplex a;
const ariles_tests::ConfigurableComplexVerbose b;
const ariles_tests::ConfigurableEmpty c;
const ariles_tests::ConfigurableFinalize d;
const ariles_tests::ConfigurableMember<int> e;
const ariles_tests::ConfigurableBase f;
const ariles_tests::ConfigurableDerived g;
const ariles_tests::ConfigurableMinimal h{};
const ariles_tests::ConfigurableNoSetDefaults k;
const ariles_tests::ConfigurablePointers l;
const ariles_tests::ConfigurableAutoDeclare m;
const ariles_tests::ConfigurableVerbose p;
const ariles_tests::ConfigurableSpecialFloats q;
const ariles_tests::ConfigurableStrictness1 r;
const ariles_tests::ConfigurableStrictness2 s;
const ariles_tests::ConfigurableAny t;
const ariles_tests::ConfigurablePointersScalar u;

return (0);
}
Loading

0 comments on commit 98d17da

Please sign in to comment.