From fe4bcea67e70b4f6df9bf8ddf8320aa8bed2b38f Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 10 Jul 2024 14:29:48 +0200 Subject: [PATCH] [All] Reduce includes to helper/set.h --- .../lagrangian/solver/LCPConstraintSolver.h | 1 - .../sofa/component/engine/analyze/Distances.h | 1 - .../dynamic/NumericalIntegrationDescriptor.h | 2 +- .../TetrahedronNumericalIntegration_test.cpp | 1 - .../TriangleNumericalIntegration_test.cpp | 1 - .../Core/src/sofa/core/CollisionModel.h | 1 + .../Core/src/sofa/core/collision/Pipeline.h | 2 +- .../Core/src/sofa/core/objectmodel/TagSet.cpp | 126 +++++++++++++++++- .../Core/src/sofa/core/objectmodel/TagSet.h | 54 +++++++- .../src/sofa/helper/MarchingCubeUtility.h | 1 - 10 files changed, 179 insertions(+), 11 deletions(-) diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.h b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.h index 5e079e5d408..0ae46b4bc29 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.h +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.h @@ -32,7 +32,6 @@ #include #include -#include #include #include diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.h b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.h index 84f1e784c70..a2becec1667 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.h +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/NumericalIntegrationDescriptor.h b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/NumericalIntegrationDescriptor.h index 1fc27d40fab..d7d0f353303 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/NumericalIntegrationDescriptor.h +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/NumericalIntegrationDescriptor.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace sofa::component::topology::container::dynamic { diff --git a/Sofa/Component/Topology/Container/Dynamic/tests/TetrahedronNumericalIntegration_test.cpp b/Sofa/Component/Topology/Container/Dynamic/tests/TetrahedronNumericalIntegration_test.cpp index da44c5f71b6..7439c68e3b2 100644 --- a/Sofa/Component/Topology/Container/Dynamic/tests/TetrahedronNumericalIntegration_test.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/tests/TetrahedronNumericalIntegration_test.cpp @@ -24,7 +24,6 @@ #include #include #include -#include // Including constraint, force and mass #include #include diff --git a/Sofa/Component/Topology/Container/Dynamic/tests/TriangleNumericalIntegration_test.cpp b/Sofa/Component/Topology/Container/Dynamic/tests/TriangleNumericalIntegration_test.cpp index ce87dfdbb4b..65c9c4cd2ab 100644 --- a/Sofa/Component/Topology/Container/Dynamic/tests/TriangleNumericalIntegration_test.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/tests/TriangleNumericalIntegration_test.cpp @@ -24,7 +24,6 @@ #include #include #include -#include // Including constraint, force and mass #include #include diff --git a/Sofa/framework/Core/src/sofa/core/CollisionModel.h b/Sofa/framework/Core/src/sofa/core/CollisionModel.h index ef650c83fbd..05305c352c6 100644 --- a/Sofa/framework/Core/src/sofa/core/CollisionModel.h +++ b/Sofa/framework/Core/src/sofa/core/CollisionModel.h @@ -23,6 +23,7 @@ #include #include +#include //todo(dmarchal 2018-06-19) I really wonder why a collision model has a dependency to a RGBAColors. #include diff --git a/Sofa/framework/Core/src/sofa/core/collision/Pipeline.h b/Sofa/framework/Core/src/sofa/core/collision/Pipeline.h index 70c04738d1c..74490c73469 100644 --- a/Sofa/framework/Core/src/sofa/core/collision/Pipeline.h +++ b/Sofa/framework/Core/src/sofa/core/collision/Pipeline.h @@ -23,7 +23,7 @@ #include -#include +#include #include diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.cpp index 2e5ce29e038..377ed3e4d3a 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.cpp @@ -20,18 +20,19 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #include +#include namespace sofa::core::objectmodel { TagSet::TagSet(const Tag& t) { - this->insert(t); + m_set.insert(t); } bool TagSet::includes(const Tag& t) const { - return this->count(t) > 0; + return m_set.count(t) > 0; } bool TagSet::includes(const TagSet& t) const @@ -70,4 +71,125 @@ bool TagSet::includes(const TagSet& t) const return true; } +bool TagSet::empty() const noexcept +{ + return m_set.empty(); +} + +std::size_t TagSet::size() const noexcept +{ + return m_set.size(); +} + +std::size_t TagSet::count(const Tag& _Keyval) const +{ + return m_set.count(_Keyval); +} + +TagSet::iterator TagSet::begin() noexcept +{ + return m_set.begin(); +} + +TagSet::const_iterator TagSet::begin() const noexcept +{ + return m_set.begin(); +} + +TagSet::iterator TagSet::end() noexcept +{ + return m_set.end(); +} + +TagSet::const_iterator TagSet::end() const noexcept +{ + return m_set.end(); +} + +TagSet::reverse_iterator TagSet::rbegin() noexcept +{ + return m_set.rbegin(); +} + +TagSet::const_reverse_iterator TagSet::rbegin() const noexcept +{ + return m_set.rbegin(); +} + +TagSet::reverse_iterator TagSet::rend() noexcept +{ + return m_set.rend(); +} + +TagSet::const_reverse_iterator TagSet::rend() const noexcept +{ + return m_set.rend(); +} + +TagSet::const_iterator TagSet::cbegin() const noexcept +{ + return m_set.cbegin(); +} + +TagSet::const_iterator TagSet::cend() const noexcept +{ + return m_set.cend(); +} + +TagSet::const_reverse_iterator TagSet::crbegin() const noexcept +{ + return m_set.crbegin(); +} + +TagSet::const_reverse_iterator TagSet::crend() const noexcept +{ + return m_set.crend(); +} + +std::pair TagSet::insert(const value_type& _Val) +{ + return m_set.insert(_Val); +} + +TagSet::iterator TagSet::erase(const_iterator _Where) noexcept +{ + return m_set.erase(_Where); +} + +TagSet::iterator TagSet::erase(const_iterator _First, + const_iterator _Last) noexcept +{ + return m_set.erase(_First, _Last); +} + +std::size_t TagSet::erase(const Tag& _Keyval) noexcept +{ + return m_set.erase(_Keyval); +} + +void TagSet::clear() noexcept +{ + m_set.clear(); +} + +std::ostream& operator<<(std::ostream& o, + const sofa::core::objectmodel::TagSet& tagSet) +{ + o << sofa::helper::join(tagSet.begin(), tagSet.end(), ' '); + return o; +} + +std::istream& operator>>(std::istream& in, + sofa::core::objectmodel::TagSet& tagSet) +{ + Tag t; + tagSet.clear(); + while(in>>t) + tagSet.insert(t); + if( in.rdstate() & std::ios_base::eofbit ) { in.clear(); } + return in; +} + + } //namespace sofa::core::objectmodel + diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.h b/Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.h index b98478895c8..a1b6313f7f7 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.h @@ -24,14 +24,20 @@ #include #include #include -#include +#include namespace sofa::core::objectmodel { -class SOFA_CORE_API TagSet : public std::set +class SOFA_CORE_API TagSet { public: + using iterator = std::set::iterator; + using const_iterator = std::set::const_iterator; + using reverse_iterator = std::set::reverse_iterator; + using const_reverse_iterator = std::set::const_reverse_iterator; + using value_type = Tag; + TagSet() = default; /// Automatic conversion between a tag and a tagset composed of this tag TagSet(const Tag& t); @@ -39,8 +45,52 @@ class SOFA_CORE_API TagSet : public std::set bool includes(const Tag& t) const; /// Returns true if this TagSet contains all specified tags bool includes(const TagSet& t) const; + + [[nodiscard]] bool empty() const noexcept; + + [[nodiscard]] std::size_t size() const noexcept; + + [[nodiscard]] std::size_t count(const Tag& _Keyval) const; + + [[nodiscard]] iterator begin() noexcept; + + [[nodiscard]] const_iterator begin() const noexcept; + + [[nodiscard]] iterator end() noexcept; + + [[nodiscard]] const_iterator end() const noexcept; + + [[nodiscard]] reverse_iterator rbegin() noexcept; + + [[nodiscard]] const_reverse_iterator rbegin() const noexcept; + + [[nodiscard]] reverse_iterator rend() noexcept; + + [[nodiscard]] const_reverse_iterator rend() const noexcept; + + [[nodiscard]] const_iterator cbegin() const noexcept; + + [[nodiscard]] const_iterator cend() const noexcept; + + [[nodiscard]] const_reverse_iterator crbegin() const noexcept; + + [[nodiscard]] const_reverse_iterator crend() const noexcept; + + std::pair insert(const value_type& _Val); + + iterator erase(const_iterator _Where) noexcept; + iterator erase(const_iterator _First, const_iterator _Last) noexcept; + std::size_t erase(const Tag& _Keyval) noexcept; + + void clear() noexcept; + +private: + std::set m_set; }; +std::ostream &operator<<(std::ostream &o, const sofa::core::objectmodel::TagSet& tagSet); +std::istream &operator>>(std::istream &in, sofa::core::objectmodel::TagSet& tagSet); + } // namespace sofa::core::objectmodel // Specialization of the defaulttype::DataTypeInfo type traits template diff --git a/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.h b/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.h index b40709f6f52..4604652fd96 100644 --- a/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.h +++ b/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.h @@ -25,7 +25,6 @@ #include #include -#include #include #include