Skip to content

Commit

Permalink
[All] Reduce includes to helper/set.h
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger committed Jul 10, 2024
1 parent b679a97 commit fe4bcea
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <sofa/linearalgebra/FullMatrix.h>
#include <sofa/linearalgebra/SparseMatrix.h>

#include <sofa/helper/set.h>
#include <sofa/helper/map.h>
#include <sofa/helper/LCPcalc.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/core/topology/BaseMeshTopology.h>
#include <sofa/type/SVector.h>
#include <sofa/helper/set.h>
#include <sofa/helper/map.h>
#include <sofa/helper/OptionsGroup.h>
#include <sofa/component/topology/container/dynamic/DynamicSparseGridTopologyContainer.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <sofa/type/Vec.h>
#include <map>
#include <sofa/type/vector.h>
#include <sofa/helper/set.h>
#include <set>

namespace sofa::component::topology::container::dynamic
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <sofa/simulation/Simulation.h>
#include <sofa/simulation/graph/DAGSimulation.h>
#include <sofa/simulation/Node.h>
#include <sofa/helper/set.h>
// Including constraint, force and mass
#include <sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.h>
#include <sofa/component/topology/container/dynamic/NumericalIntegrationDescriptor.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <sofa/simulation/Simulation.h>
#include <sofa/simulation/graph/DAGSimulation.h>
#include <sofa/simulation/Node.h>
#include <sofa/helper/set.h>
// Including constraint, force and mass
#include <sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h>
#include <sofa/component/topology/container/dynamic/NumericalIntegrationDescriptor.h>
Expand Down
1 change: 1 addition & 0 deletions Sofa/framework/Core/src/sofa/core/CollisionModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <sofa/core/objectmodel/BaseObject.h>
#include <sofa/core/CollisionElement.h>
#include <sofa/helper/set.h>

//todo(dmarchal 2018-06-19) I really wonder why a collision model has a dependency to a RGBAColors.
#include <sofa/type/RGBAColor.h>
Expand Down
2 changes: 1 addition & 1 deletion Sofa/framework/Core/src/sofa/core/collision/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <sofa/core/objectmodel/BaseObject.h>

#include <sofa/helper/set.h>
#include <set>
#include <sofa/type/vector.h>


Expand Down
126 changes: 124 additions & 2 deletions Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
* Contact information: [email protected] *
******************************************************************************/
#include <sofa/core/objectmodel/TagSet.h>
#include <sofa/helper/StringUtils.h>

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
Expand Down Expand Up @@ -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::iterator, bool> 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

54 changes: 52 additions & 2 deletions Sofa/framework/Core/src/sofa/core/objectmodel/TagSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,73 @@
#include <sofa/core/config.h>
#include <sofa/core/objectmodel/Tag.h>
#include <sofa/defaulttype/typeinfo/TypeInfo_Set.h>
#include <sofa/helper/set.h>
#include <set>

namespace sofa::core::objectmodel
{

class SOFA_CORE_API TagSet : public std::set<Tag>
class SOFA_CORE_API TagSet
{
public:
using iterator = std::set<Tag>::iterator;
using const_iterator = std::set<Tag>::const_iterator;
using reverse_iterator = std::set<Tag>::reverse_iterator;
using const_reverse_iterator = std::set<Tag>::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);
/// Returns true if this TagSet contains specified tag
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<iterator, bool> 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<Tag> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <sofa/type/Vec.h>
#include <sofa/type/vector.h>
#include <sofa/helper/set.h>
#include <sofa/helper/io/Mesh.h>
#include <map>

Expand Down

0 comments on commit fe4bcea

Please sign in to comment.