From 38b8f34b2884768172dfd2394b5f44694e31ff54 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 11 Oct 2023 19:19:44 -0400 Subject: [PATCH] refactor: move impl into .cpp + fix include paths --- CMakeLists.txt | 19 ++++++++------- cmake/webutilConfig.cmake.in | 2 ++ include/xo/webutil/Alist.hpp | 14 ++--------- include/xo/webutil/HttpEndpointDescr.hpp | 20 +++++----------- include/xo/webutil/StreamEndpointDescr.hpp | 19 ++++----------- src/webutil/Alist.cpp | 28 ++++++++++++++++++++++ src/webutil/CMakeLists.txt | 14 +++++++++++ src/webutil/HttpEndpointDescr.cpp | 27 +++++++++++++++++++++ src/webutil/StreamEndpointDescr.cpp | 28 ++++++++++++++++++++++ 9 files changed, 122 insertions(+), 49 deletions(-) create mode 100644 src/webutil/Alist.cpp create mode 100644 src/webutil/CMakeLists.txt create mode 100644 src/webutil/HttpEndpointDescr.cpp create mode 100644 src/webutil/StreamEndpointDescr.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index dcce42b2..04cc53f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,20 +24,19 @@ add_code_coverage() add_code_coverage_all_targets(EXCLUDE /nix/store/* utest/*) # ---------------------------------------------------------------- +# common c++ settings + +# PROJECT_CXX_FLAGS: bespoke for this project - usually empty +set(PROJECT_CXX_FLAGS "") +#set(PROJECT_CXX_FLAGS "-fconcepts-diagnostics-depth=2") +add_definitions(${PROJECT_CXX_FLAGS}) xo_toplevel_compile_options() # ---------------------------------------------------------------- +# sources -# header-only library. -# see [[https://stackoverflow.com/questions/47718485/install-and-export-interface-only-library-cmake]] -# -xo_add_headeronly_library(webutil) - -# ---------------------------------------------------------------- -# standard install - -xo_install_library3(webutil ${PROJECT_NAME}Targets) +add_subdirectory(src/webutil) # ---------------------------------------------------------------- # provide find_package() support @@ -47,4 +46,6 @@ xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets # ---------------------------------------------------------------- # install bespoke targets, if any +xo_install_include_tree() + #install(TARGETS example DESTINATION bin/xo-webutil/example) diff --git a/cmake/webutilConfig.cmake.in b/cmake/webutilConfig.cmake.in index c44284f2..79a9df3d 100644 --- a/cmake/webutilConfig.cmake.in +++ b/cmake/webutilConfig.cmake.in @@ -1,4 +1,6 @@ @PACKAGE_INIT@ +include(CMakeFindDependencyMacro) +find_dependency(callback) include("${CMAKE_CURRENT_LIST_DIR}/webutilTargets.cmake") check_required_components("@PROJECT_NAME@") diff --git a/include/xo/webutil/Alist.hpp b/include/xo/webutil/Alist.hpp index ccb317b3..4bc5a305 100644 --- a/include/xo/webutil/Alist.hpp +++ b/include/xo/webutil/Alist.hpp @@ -19,19 +19,9 @@ namespace xo { Alist() = default; /* lookup association by name */ - std::string_view lookup(std::string n) const { - for (auto const & ix : this->assoc_v_) { - if (ix.first == n) { - return ix.second; - } - } + std::string_view lookup(std::string n) const; - return ""; - } /*lookup*/ - - void push_back(std::string n, std::string v) { - this->assoc_v_.push_back(std::make_pair(std::move(n), std::move(v))); - } + void push_back(std::string n, std::string v); private: std::vector> assoc_v_; diff --git a/include/xo/webutil/HttpEndpointDescr.hpp b/include/xo/webutil/HttpEndpointDescr.hpp index 97ff4cee..f3598cbb 100644 --- a/include/xo/webutil/HttpEndpointDescr.hpp +++ b/include/xo/webutil/HttpEndpointDescr.hpp @@ -5,11 +5,10 @@ #pragma once -#include "web_util/Alist.hpp" -#include "refcnt/Refcounted.hpp" -#include "indentlog/print/tag.hpp" -#include "indentlog/print/tostr.hpp" +#include "Alist.hpp" +#include "xo/refcnt/Refcounted.hpp" #include +#include namespace xo { namespace web { @@ -26,21 +25,14 @@ namespace xo { class HttpEndpointDescr { public: HttpEndpointDescr(std::string uri_pattern, - HttpEndpointFn endpoint_fn) - : uri_pattern_{std::move(uri_pattern)}, - endpoint_fn_{std::move(endpoint_fn)} - {} + HttpEndpointFn endpoint_fn); std::string const & uri_pattern() const { return uri_pattern_; } HttpEndpointFn const & endpoint_fn() const { return endpoint_fn_; } - void display(std::ostream & os) const { - using xo::xtag; + void display(std::ostream & os) const; - os << ""; - } /*display*/ - - std::string display_string() const { return xo::tostr(*this); } + std::string display_string() const; private: /* unique pattern in URI-space for this endpoint. diff --git a/include/xo/webutil/StreamEndpointDescr.hpp b/include/xo/webutil/StreamEndpointDescr.hpp index 1b361610..78053008 100644 --- a/include/xo/webutil/StreamEndpointDescr.hpp +++ b/include/xo/webutil/StreamEndpointDescr.hpp @@ -6,10 +6,8 @@ #pragma once #include "Alist.hpp" -#include "callback/CallbackSet.hpp" -#include "refcnt/Refcounted.hpp" -#include "indentlog/print/tag.hpp" -#include "indentlog/print/tostr.hpp" +#include "xo/callback/CallbackSet.hpp" +#include "xo/refcnt/Refcounted.hpp" #include namespace xo { @@ -30,22 +28,15 @@ namespace xo { public: StreamEndpointDescr(std::string uri_pattern, StreamSubscribeFn subscribe_fn, - StreamUnsubscribeFn unsubscribe_fn) - : uri_pattern_{std::move(uri_pattern)}, - subscribe_fn_{std::move(subscribe_fn)}, - unsubscribe_fn_{std::move(unsubscribe_fn)} {} + StreamUnsubscribeFn unsubscribe_fn); std::string const & uri_pattern() const { return uri_pattern_; } StreamSubscribeFn const & subscribe_fn() const { return subscribe_fn_; } StreamUnsubscribeFn const & unsubscribe_fn() const { return unsubscribe_fn_; } - void display(std::ostream & os) const { - using xo::xtag; + void display(std::ostream & os) const; - os << ""; - } /*display*/ - - std::string display_string() const { return xo::tostr(*this); } + std::string display_string() const; private: /* unique pattern in URI-space for this endpoint diff --git a/src/webutil/Alist.cpp b/src/webutil/Alist.cpp new file mode 100644 index 00000000..73905106 --- /dev/null +++ b/src/webutil/Alist.cpp @@ -0,0 +1,28 @@ +/* @file Alist.cpp */ + +#include "Alist.hpp" + +namespace xo { + namespace web { + /* lookup association by name */ + std::string_view + Alist::lookup(std::string n) const { + for (auto const & ix : this->assoc_v_) { + if (ix.first == n) { + return ix.second; + } + } + + return ""; + } /*lookup*/ + + void + Alist::push_back(std::string n, std::string v) { + this->assoc_v_.push_back(std::make_pair(std::move(n), std::move(v))); + } + } /*namespace web*/ +} /*namespace xo*/ + + + +/* end Alist.cpp */ diff --git a/src/webutil/CMakeLists.txt b/src/webutil/CMakeLists.txt new file mode 100644 index 00000000..57f96726 --- /dev/null +++ b/src/webutil/CMakeLists.txt @@ -0,0 +1,14 @@ +# webutil/CMakeLists.txt + +set(SELF_LIB webutil) +set(SELF_SRCS StreamEndpointDescr.cpp HttpEndpointDescr.cpp Alist.cpp) + +# reminder: can't be header-only library, because depends on non-header-only callback (bc of non-header-only refcnt) +xo_add_shared_library(${SELF_LIB} ${PROJECT_VERSION} 1 ${SELF_SRCS}) + +# ---------------------------------------------------------------- +# external dependencies + +xo_dependency(${SELF_LIB} callback) + +# end CMakeLists.txt diff --git a/src/webutil/HttpEndpointDescr.cpp b/src/webutil/HttpEndpointDescr.cpp new file mode 100644 index 00000000..fb9ab261 --- /dev/null +++ b/src/webutil/HttpEndpointDescr.cpp @@ -0,0 +1,27 @@ +/* @file HttpEndpointDescr.cpp */ + +#include "HttpEndpointDescr.hpp" +#include "xo/indentlog/print/tag.hpp" +#include "xo/indentlog/print/tostr.hpp" + +namespace xo { + namespace web { + HttpEndpointDescr::HttpEndpointDescr(std::string uri_pattern, + HttpEndpointFn endpoint_fn) + : uri_pattern_{std::move(uri_pattern)}, + endpoint_fn_{std::move(endpoint_fn)} + {} + + void + HttpEndpointDescr::display(std::ostream & os) const { + os << ""; + } /*display*/ + + std::string + HttpEndpointDescr::display_string() const { return tostr(*this); } + } /*namespace web*/ + +} /*namespace xo*/ + + +/* end HttpEndpointDescr.cpp */ diff --git a/src/webutil/StreamEndpointDescr.cpp b/src/webutil/StreamEndpointDescr.cpp new file mode 100644 index 00000000..03c2e961 --- /dev/null +++ b/src/webutil/StreamEndpointDescr.cpp @@ -0,0 +1,28 @@ +/* @file StreamEndpointDescr.cpp */ + +#include "StreamEndpointDescr.hpp" +#include "xo/indentlog/print/tag.hpp" +#include "xo/indentlog/print/tostr.hpp" + +namespace xo { + namespace web { + StreamEndpointDescr::StreamEndpointDescr(std::string uri_pattern, + StreamSubscribeFn subscribe_fn, + StreamUnsubscribeFn unsubscribe_fn) + : uri_pattern_{std::move(uri_pattern)}, + subscribe_fn_{std::move(subscribe_fn)}, + unsubscribe_fn_{std::move(unsubscribe_fn)} + {} + + void + StreamEndpointDescr::display(std::ostream & os) const { + os << ""; + } /*display*/ + + std::string + StreamEndpointDescr::display_string() const { return tostr(*this); } + } /*namespace web*/ +} /*namespace xo*/ + + +/* end StreamEndpointDescr.cpp */