refactor: move impl into .cpp + fix include paths

This commit is contained in:
Roland Conybeare 2023-10-11 19:19:44 -04:00
commit 38b8f34b28
9 changed files with 123 additions and 50 deletions

View file

@ -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)

View file

@ -1,4 +1,6 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(callback)
include("${CMAKE_CURRENT_LIST_DIR}/webutilTargets.cmake")
check_required_components("@PROJECT_NAME@")

View file

@ -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<std::pair<std::string, std::string>> assoc_v_;

View file

@ -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 <functional>
#include <string>
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 << "<HttpEndpointDescr" << xtag("uri_pattern", uri_pattern_) << ">";
} /*display*/
std::string display_string() const { return xo::tostr(*this); }
std::string display_string() const;
private:
/* unique pattern in URI-space for this endpoint.

View file

@ -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 <functional>
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 << "<StreamEndpointDescr" << xtag("uri_pattern", uri_pattern_) << ">";
} /*display*/
std::string display_string() const { return xo::tostr(*this); }
std::string display_string() const;
private:
/* unique pattern in URI-space for this endpoint

28
src/webutil/Alist.cpp Normal file
View file

@ -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 */

View file

@ -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

View file

@ -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 << "<HttpEndpointDescr" << xtag("uri_pattern", uri_pattern_) << ">";
} /*display*/
std::string
HttpEndpointDescr::display_string() const { return tostr(*this); }
} /*namespace web*/
} /*namespace xo*/
/* end HttpEndpointDescr.cpp */

View file

@ -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 << "<StreamEndpointDescr" << xtag("uri_pattern", uri_pattern_) << ">";
} /*display*/
std::string
StreamEndpointDescr::display_string() const { return tostr(*this); }
} /*namespace web*/
} /*namespace xo*/
/* end StreamEndpointDescr.cpp */