Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-definition from lib and headers #172

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion binds/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pybind11_add_module(_morphio

target_include_directories(_morphio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_SOURCE_DIR}/include
)

target_link_libraries(_morphio
Expand Down
2 changes: 1 addition & 1 deletion binds/python/bindings_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ morphio::Points array_to_points(py::array_t<float>& buf);
py::array_t<float> span_array_to_ndarray(const morphio::range<const morphio::Point>& span);

template <typename T>
py::array_t<float> span_to_ndarray(const morphio::range<const T>& span) {
inline py::array_t<float> span_to_ndarray(const morphio::range<const T>& span) {
const void* ptr = static_cast<const void*>(span.data());
const auto buffer_info = py::buffer_info(
// Cast from (const void*) to (void*) for function signature matching
Expand Down
4 changes: 2 additions & 2 deletions include/morphio/mito_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class MitoSection: public SectionBase<MitoSection>
range<const float> relativePathLengths() const;

protected:
MitoSection(uint32_t id_, const std::shared_ptr<Property::Properties>& morphology)
: SectionBase(id_, morphology) {}
using SectionBase<MitoSection>::SectionBase;

friend MitoSection Mitochondria::section(uint32_t) const;
friend class SectionBase<MitoSection>;
friend class mut::MitoSection;
Expand Down
3 changes: 1 addition & 2 deletions include/morphio/section.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ class Section: public SectionBase<Section>
friend class SectionBase<Section>;

protected:
Section(uint32_t id_, const std::shared_ptr<Property::Properties>& properties)
: SectionBase(id_, properties) {}
using SectionBase<Section>::SectionBase;
};

// explicit instanciation
Expand Down
22 changes: 4 additions & 18 deletions include/morphio/section_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ template <typename T>
class SectionBase
{
public:
SectionBase()
inline SectionBase()
: _id(0) {}

SectionBase(const SectionBase& section);

SectionBase& operator=(const SectionBase& other);

inline bool operator==(const SectionBase& other) const noexcept;
inline bool operator!=(const SectionBase& other) const noexcept;
bool operator==(const SectionBase& other) const noexcept;
bool operator!=(const SectionBase& other) const noexcept;

/**
* Return true if this section is a root section (parent ID == -1)
Expand All @@ -52,7 +52,7 @@ class SectionBase
std::vector<T> children() const;

/** Return the ID of this section. */
inline uint32_t id() const noexcept;
uint32_t id() const noexcept;

protected:
SectionBase(uint32_t id, const std::shared_ptr<Property::Properties>& properties);
Expand All @@ -64,20 +64,6 @@ class SectionBase
std::shared_ptr<Property::Properties> _properties;
};

template <typename T>
inline bool SectionBase<T>::operator==(const SectionBase& other) const noexcept {
return other._id == _id && other._properties == _properties;
}

template <typename T>
inline bool SectionBase<T>::operator!=(const SectionBase& other) const noexcept {
return !(*this == other);
}

template <typename T>
inline uint32_t SectionBase<T>::id() const noexcept {
return _id;
}

} // namespace morphio

Expand Down
33 changes: 24 additions & 9 deletions include/morphio/section_base.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace morphio {
template <typename T>
SectionBase<T>::SectionBase(const uint32_t id_,
const std::shared_ptr<Property::Properties>& properties)
inline SectionBase<T>::SectionBase(const uint32_t id_,
const std::shared_ptr<Property::Properties>& properties)
: _id(id_)
, _properties(properties) {
const auto& sections = properties->get<typename T::SectionId>();
Expand All @@ -27,13 +27,13 @@ SectionBase<T>::SectionBase(const uint32_t id_,
}

template <typename T>
SectionBase<T>::SectionBase(const SectionBase& other)
inline SectionBase<T>::SectionBase(const SectionBase& other)
: _id(other._id)
, _range(other._range)
, _properties(other._properties) {}

template <typename T>
SectionBase<T>& SectionBase<T>::operator=(const SectionBase& section) {
inline SectionBase<T>& SectionBase<T>::operator=(const SectionBase& section) {
if (&section == this)
return *this;
_id = section._id;
Expand All @@ -44,7 +44,7 @@ SectionBase<T>& SectionBase<T>::operator=(const SectionBase& section) {

template <typename T>
template <typename TProperty>
range<const typename TProperty::Type> SectionBase<T>::get() const {
inline range<const typename TProperty::Type> SectionBase<T>::get() const {
const auto& data = _properties->get<TProperty>();
if (data.empty())
return {};
Expand All @@ -54,23 +54,23 @@ range<const typename TProperty::Type> SectionBase<T>::get() const {
}

template <typename T>
bool SectionBase<T>::isRoot() const {
inline bool SectionBase<T>::isRoot() const {
return _properties->get<typename T::SectionId>()[_id][1] == -1;
}

template <typename T>
T SectionBase<T>::parent() const {
inline T SectionBase<T>::parent() const {
if (isRoot())
throw MissingParentError("Cannot call Section::parent() on a root node (section id=" +
std::to_string(_id) + ").");
std::to_string(_id) + ").");

const auto _parent = static_cast<unsigned int>(
_properties->get<typename T::SectionId>()[_id][1]);
return {_parent, _properties};
}

template <typename T>
std::vector<T> SectionBase<T>::children() const {
inline std::vector<T> SectionBase<T>::children() const {
std::vector<T> result;
try {
const std::vector<uint32_t>& _children = _properties->children<typename T::SectionId>().at(
Expand All @@ -85,4 +85,19 @@ std::vector<T> SectionBase<T>::children() const {
}
}

template <typename T>
inline bool SectionBase<T>::operator==(const SectionBase& other) const noexcept {
return other._id == _id && other._properties == _properties;
}

template <typename T>
inline bool SectionBase<T>::operator!=(const SectionBase& other) const noexcept {
return !(*this == other);
}

template <typename T>
inline uint32_t SectionBase<T>::id() const noexcept {
return _id;
}

} // namespace morphio
66 changes: 35 additions & 31 deletions include/morphio/section_iterators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,47 @@
#include <morphio/exceptions.h>
#include <morphio/types.h>

namespace morphio {
namespace detail {

template <typename SectionT, typename MorphologyT>
std::vector<SectionT> getChildren(const MorphologyT& morphology) noexcept {
inline std::vector<SectionT> getChildren(const MorphologyT& morphology) noexcept {
return morphology.rootSections();
}

template <typename SectionT>
std::vector<SectionT> getChildren(const SectionT& section) {
inline std::vector<SectionT> getChildren(const SectionT& section) {
return section.children();
}

template <typename SectionT>
std::vector<std::shared_ptr<SectionT>> getChildren(const std::shared_ptr<SectionT>& section) {
inline std::vector<std::shared_ptr<SectionT>> getChildren(
const std::shared_ptr<SectionT>& section) {
return section->children();
}

template <typename SectionT>
bool isRoot(const SectionT& current) {
inline bool isRoot(const SectionT& current) {
return current.isRoot();
}

template <typename SectionT>
bool isRoot(const std::shared_ptr<SectionT>& current) {
inline bool isRoot(const std::shared_ptr<SectionT>& current) {
return current->isRoot();
}

template <typename SectionT>
SectionT getParent(const SectionT& current) {
inline SectionT getParent(const SectionT& current) {
return current.parent();
}

template <typename SectionT>
std::shared_ptr<SectionT> getParent(const std::shared_ptr<SectionT>& current) {
inline std::shared_ptr<SectionT> getParent(const std::shared_ptr<SectionT>& current) {
return current->parent();
}
} // namespace detail
} // namespace morphio


namespace morphio {

Expand All @@ -61,16 +65,16 @@ class breadth_iterator_t

breadth_iterator_t() = default;

inline explicit breadth_iterator_t(const SectionT& section);
inline explicit breadth_iterator_t(const MorphologyT& morphology);
inline breadth_iterator_t(const breadth_iterator_t& other);
explicit breadth_iterator_t(const SectionT& section);
explicit breadth_iterator_t(const MorphologyT& morphology);
breadth_iterator_t(const breadth_iterator_t& other);

inline SectionT operator*() const;
SectionT operator*() const;

inline breadth_iterator_t& operator++();
inline breadth_iterator_t operator++(int);
breadth_iterator_t& operator++();
breadth_iterator_t operator++(int);

inline bool operator==(const breadth_iterator_t& other) const;
bool operator==(const breadth_iterator_t& other) const;
bool operator!=(const breadth_iterator_t& other) const;

private:
Expand All @@ -89,17 +93,17 @@ class depth_iterator_t

depth_iterator_t() = default;

inline explicit depth_iterator_t(const SectionT& section);
inline explicit depth_iterator_t(const MorphologyT& morphology);
inline depth_iterator_t(const depth_iterator_t& other);
explicit depth_iterator_t(const SectionT& section);
explicit depth_iterator_t(const MorphologyT& morphology);
depth_iterator_t(const depth_iterator_t& other);

inline SectionT operator*() const;
SectionT operator*() const;

inline depth_iterator_t& operator++();
inline depth_iterator_t operator++(int);
depth_iterator_t& operator++();
depth_iterator_t operator++(int);

inline bool operator==(const depth_iterator_t& other) const;
inline bool operator!=(const depth_iterator_t& other) const;
bool operator==(const depth_iterator_t& other) const;
bool operator!=(const depth_iterator_t& other) const;

private:
std::deque<SectionT> deque_;
Expand All @@ -115,18 +119,18 @@ class upstream_iterator_t
using pointer = SectionT*;
using reference = SectionT&;

inline upstream_iterator_t();
inline explicit upstream_iterator_t(const SectionT& section);
inline upstream_iterator_t(const upstream_iterator_t& other);
inline ~upstream_iterator_t();
upstream_iterator_t();
explicit upstream_iterator_t(const SectionT& section);
upstream_iterator_t(const upstream_iterator_t& other);
~upstream_iterator_t();

inline SectionT operator*() const;
SectionT operator*() const;

inline upstream_iterator_t& operator++();
inline upstream_iterator_t operator++(int);
upstream_iterator_t& operator++();
upstream_iterator_t operator++(int);

inline bool operator==(const upstream_iterator_t& other) const;
inline bool operator!=(const upstream_iterator_t& other) const;
bool operator==(const upstream_iterator_t& other) const;
bool operator!=(const upstream_iterator_t& other) const;

private:
// This is a workaround for not having std::optional until c++17.
Expand Down
12 changes: 6 additions & 6 deletions include/morphio/shared_utils.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace morphio {
template <typename ContainerDiameters, typename ContainerPoints>
float _somaSurface(const SomaType type,
const ContainerDiameters& diameters,
const ContainerPoints& points) {
inline float _somaSurface(const SomaType type,
const ContainerDiameters& diameters,
const ContainerPoints& points) {
size_t size = points.size();
if (size == 0)
return 0.;
Expand Down Expand Up @@ -48,13 +48,13 @@ float _somaSurface(const SomaType type,
}
}
template <typename T>
void _appendVector(std::vector<T>& to, const std::vector<T>& from, int offset) {
inline void _appendVector(std::vector<T>& to, const std::vector<T>& from, int offset) {
to.insert(to.end(), from.begin() + offset, from.end());
}

template <typename T>
std::vector<typename T::Type> copySpan(const std::vector<typename T::Type>& data,
SectionRange range) {
inline std::vector<typename T::Type> copySpan(const std::vector<typename T::Type>& data,
SectionRange range) {
if (data.empty())
return {};

Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ add_library(morphio_obj OBJECT ${MORPHIO_SOURCES})

target_include_directories(morphio_obj
PUBLIC
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/include
)

target_include_directories(morphio_obj
Expand Down