Skip to content

Commit

Permalink
Merge pull request #27 from SolidWallOfCode/dev-1-2-1
Browse files Browse the repository at this point in the history
Version 1.2.1
  • Loading branch information
SolidWallOfCode authored Apr 23, 2020
2 parents 2cfb9b8 + 86de876 commit ef3f916
Show file tree
Hide file tree
Showing 51 changed files with 412 additions and 130 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ project("Solid Wall Of C++ Library")
set(INSTALL_DIR ${CMAKE_HOME_DIRECTORY})

# Fortunately this has no external dependencies so the set up can be simple.
add_subdirectory(swoc++)
add_subdirectory(code)
add_subdirectory(unit_tests)
add_subdirectory(example)
add_subdirectory(doc EXCLUDE_FROM_ALL)

# Find all of the directories subject to clang formatting and make a target to do the format.
set(_CLANG_DIRS "")
get_target_property(_TMP swoc++ CLANG_FORMAT_DIRS)
get_target_property(_TMP libswoc CLANG_FORMAT_DIRS)
list(APPEND _CLANG_DIRS ${_TMP})
get_target_property(_TMP test_libswoc CLANG_FORMAT_DIRS)
list(APPEND _CLANG_DIRS ${_TMP})
Expand Down
2 changes: 1 addition & 1 deletion Sconstruct
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from parts import *

Part("swoc++/swoc++.part")
Part("code/libswoc.part")
Part("unit_tests/unit_tests.part")
29 changes: 14 additions & 15 deletions swoc++/CMakeLists.txt → code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12)

project(lib-swoc++ CXX)
set(LIBSWOC_VERSION "1.2.0")
project(Lib-SWOC CXX)
set(LIBSWOC_VERSION "1.2.1")
set(CMAKE_CXX_STANDARD 17)
include(GNUInstallDirs)

Expand Down Expand Up @@ -44,38 +44,37 @@ set(CC_FILES
src/TextView.cc
)

add_library(swoc++ STATIC ${CC_FILES})
#add_compile_options(-Wall -Wextra -Werror -Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow -Wno-invalid-offsetof)
target_compile_options(swoc++ PRIVATE -Wall -Wextra -Werror -Wnon-virtual-dtor -Wno-unused-parameter -Wno-stringop-overflow)
add_library(libswoc STATIC ${CC_FILES})
target_compile_options(libswoc PRIVATE -Wall -Wextra -Werror -Wnon-virtual-dtor -Wpedantic)

# Not quite sure how this works, but I think it generates one of two paths depending on the context.
# That is, the generator functions return non-empty strings only in the corresponding context.
target_include_directories(swoc++
target_include_directories(libswoc
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)

# These install target variables are created by GNUInstallDirs.
install(TARGETS swoc++
EXPORT swoc++-config
install(TARGETS libswoc
EXPORT libswoc-config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY include/swoc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(EXPORT swoc++-config
NAMESPACE swoc++::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/swoc++
install(EXPORT libswoc-config
NAMESPACE libswoc::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libswoc
)

set(PKG_CONFIG_FILE ${CMAKE_BINARY_DIR}/libswoc++.pc)
configure_file("libswoc++.pc.cmake" ${PKG_CONFIG_FILE} @ONLY)
set(PKG_CONFIG_FILE ${CMAKE_BINARY_DIR}/libswoc.pc)
configure_file("libswoc.pc.cmake" ${PKG_CONFIG_FILE} @ONLY)
install(FILES ${PKG_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)

# Alledgedly this makes the targets "importable from the build directory" but I see no evidence of that.
# AFAICT the file isn't created at all even with this enabled.
#export(TARGETS swoc++ FILE libswoc++-config.cmake)
#export(TARGETS libswoc FILE libswoc-config.cmake)

set(CLANG_DIRS )

set_target_properties(swoc++ PROPERTIES CLANG_FORMAT_DIRS "${PROJECT_SOURCE_DIR}/src;${PROJECT_SOURCE_DIR}/include")
set_target_properties(libswoc PROPERTIES CLANG_FORMAT_DIRS "${PROJECT_SOURCE_DIR}/src;${PROJECT_SOURCE_DIR}/include")
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ template<typename T> class DiscreteRange {
*/
metric_type const& max() const;

/// Test for equality.
bool operator == (self_type const& that) const {
return _min == that._min && _max == that._max;
}

/// Test for inequality.
bool operator != (self_type const& that) const {
return _min != that._min | _max != that._max;
}

/** Check if a value is in @a this range.
*
* @param m Metric value to check.
Expand Down Expand Up @@ -971,6 +981,37 @@ DiscreteSpace<METRIC, PAYLOAD>::insert_after(DiscreteSpace::Node *spot, Discrete
_root = static_cast<Node *>(node->rebalance_after_insert());
}

template<typename METRIC, typename PAYLOAD>
DiscreteSpace<METRIC, PAYLOAD>&
DiscreteSpace<METRIC, PAYLOAD>::erase(DiscreteSpace::range_type const& range) {
Node *n = this->lower_bound(range.min()); // current node.
while (n) {
auto nn = next(n); // cache in case @a n disappears.
if (n->min() > range.max()) { // cleared the target range, done.
break;
}

if (n->max() >= range.min()) { // some overlap
if (n->max() <= range.max()) { // pure left overlap, clip.
if (n->min() >= range.min()) { // covered, remove.
this->remove(n);
} else { // stub on the left, clip to that.
n->assign_max(--metric_type{range.min()});
}
} else if (n->min() >= range.min()) { // pure left overlap, clip.
n->assign_min(++metric_type{range.max()});
} else { // @a n covers @a range, must split.
auto y = _fa.make(range_type{n->min(), --metric_type{range.min()}}, n->payload());
n->assign_min(++metric_type{range.max()});
this->insert_before(n, y);
break;
}
}
n = nn;
}
return *this;
}

template<typename METRIC, typename PAYLOAD>
DiscreteSpace<METRIC, PAYLOAD>&
DiscreteSpace<METRIC, PAYLOAD>::mark(DiscreteSpace::range_type const& range
Expand All @@ -979,16 +1020,15 @@ DiscreteSpace<METRIC, PAYLOAD>::mark(DiscreteSpace::range_type const& range
Node *x = nullptr; // New node, gets set if we re-use an existing one.
Node *y = nullptr; // Temporary for removing and advancing.

METRIC max_plus_1 = range.max();
++max_plus_1; // careful to use this only in places there's no chance of overflow.
// Use carefully, only in situations where it is known there is no overflow.
auto max_plus_1 = ++metric_type{range.max()};

/* We have lots of special cases here primarily to minimize memory
allocation by re-using an existing node as often as possible.
*/
if (n) {
// Watch for wrap.
METRIC min_minus_1 = range.min();
--min_minus_1;
auto min_minus_1 = --metric_type{range.min()};
if (n->min() == range.min()) {
// Could be another span further left which is adjacent.
// Coalesce if the data is the same. min_minus_1 is OK because
Expand All @@ -1006,7 +1046,7 @@ DiscreteSpace<METRIC, PAYLOAD>::mark(DiscreteSpace::range_type const& range
return *this; // request is covered by existing span with the same data
} else {
// request span is covered by existing span.
x = new Node{range, payload}; //
x = _fa.make(range, payload); //
n->assign_min(max_plus_1); // clip existing.
this->insert_before(n, x);
return *this;
Expand Down Expand Up @@ -1187,7 +1227,7 @@ DiscreteSpace<METRIC, PAYLOAD>::fill(DiscreteSpace::range_type const& range
}
} else { // no carry node.
if (max < n->_min) { // entirely before next span.
this->insert_before(n, new Node(min, max, payload));
this->insert_before(n, _fa.make(min, max, payload));
return *this;
} else {
if (min < n->_min) { // leading section, need node.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ ptr_ref_cast(P *& p) {
T **_t;
} u{&p};
return *(u._t);
};
}

/** Utility class to provide intrusive links.
*
Expand Down Expand Up @@ -738,7 +738,7 @@ template<typename L>
auto
IntrusiveDList<L>::erase(const iterator& loc) -> iterator {
return this->iterator_for(this->erase(loc._v));
};
}

template<typename L>
auto
Expand All @@ -763,7 +763,7 @@ IntrusiveDList<L>::erase(const iterator& first, const iterator& limit) -> iterat
};

return {limit._v, this};
};
}

template<typename L>
auto
Expand All @@ -781,43 +781,43 @@ template<typename L>
size_t
IntrusiveDList<L>::count() const {
return _count;
};
}

template<typename L>
auto
IntrusiveDList<L>::begin() const -> const_iterator {
return const_iterator{this, _head};
};
}

template<typename L>
auto
IntrusiveDList<L>::begin() -> iterator {
return iterator{this, _head};
};
}

template<typename L>
auto
IntrusiveDList<L>::end() const -> const_iterator {
return const_iterator{this, nullptr};
};
}

template<typename L>
auto
IntrusiveDList<L>::end() -> iterator {
return iterator{this, nullptr};
};
}

template<typename L>
auto
IntrusiveDList<L>::iterator_for(value_type *v) -> iterator {
return iterator{this, v};
};
}

template<typename L>
auto
IntrusiveDList<L>::iterator_for(const value_type *v) const -> const_iterator {
return const_iterator{this, v};
};
}

template<typename L>
auto
Expand Down Expand Up @@ -849,7 +849,7 @@ IntrusiveDList<L>::clear() -> self_type& {
_head = _tail = nullptr;
_count = 0;
return *this;
};
}

namespace detail {
// Make @c apply more convenient by allowing the function to take a reference type or pointer type
Expand Down Expand Up @@ -884,6 +884,6 @@ template<typename F>
auto
IntrusiveDList<L>::apply(F&& f) -> self_type& {
return detail::Intrusive_DList_Apply(*this, f);
};
}

}} // namespace swoc
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions swoc++/include/swoc/MemSpan.h → code/include/swoc/MemSpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,24 +920,24 @@ MemSpan<void>::view() const {
/// @cond NO_DOXYGEN
// STL tuple support - this allows the @c MemSpan to be used as a tuple of a pointer
// and size.
namespace std
{
template <size_t IDX, typename R> class tuple_element<IDX, swoc::MemSpan<R>> {
namespace std {
template<size_t IDX, typename R> class tuple_element<IDX, swoc::MemSpan<R>> {
static_assert("swoc::MemSpan tuple index out of range");
};

template <typename R> class tuple_element<0, swoc::MemSpan<R>> {
template<typename R> class tuple_element<0, swoc::MemSpan<R>> {
public:
using type = R *;
};

template <typename R> class tuple_element<1, swoc::MemSpan<R>> {
template<typename R> class tuple_element<1, swoc::MemSpan<R>> {
public:
using type = size_t;
};

template <typename R> class tuple_size<swoc::MemSpan<R>> : public std::integral_constant<size_t, 2> {};
template<typename R> class tuple_size<swoc::MemSpan<R>> : public std::integral_constant<size_t, 2> {
};

}; // namespace std
} // namespace std

/// @endcond
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class TextView : public std::string_view {
*
* @note @c c_str must be a null terminated string. The null byte is not included in the view.
*/
self_type& assign(char const* c_str);;
self_type& assign(char const* c_str);

/// Explicitly set the start @a ptr and size @a n of the view.
self_type &assign(char const *ptr, size_t n);
Expand Down Expand Up @@ -819,7 +819,7 @@ svto_radix(swoc::TextView &src) {
++src;
}
return zret;
};
}

template <int N>
uintmax_t
Expand Down
Loading

0 comments on commit ef3f916

Please sign in to comment.