Radium Engine  1.5.0
ObjectWithSemantic.hpp
1 #pragma once
2 
3 #include <Core/RaCore.hpp>
4 
5 #include <cstdarg>
6 #include <set>
7 
8 namespace Ra {
9 namespace Core {
10 namespace Utils {
17 class RA_CORE_API ObjectWithSemantic
18 {
19  public:
20  using SemanticName = std::string;
21 
23  using SemanticNameCollection = std::set<SemanticName>;
24 
25  inline explicit ObjectWithSemantic( const ObjectWithSemantic& other ) :
26  m_names { other.m_names } {}
27 
28  virtual inline ~ObjectWithSemantic() = default;
29 
30  inline bool hasSemantic( const SemanticName& name ) const {
31  return m_names.find( name ) != m_names.end();
32  }
33 
34  inline const SemanticNameCollection& semantics() const { return m_names; }
35 
36  inline ObjectWithSemantic& operator=( const ObjectWithSemantic& other ) {
37  CORE_UNUSED( other );
38  CORE_ASSERT( m_names == other.m_names, "Try to assign object with different semantics" );
39  return *this;
40  }
41  inline ObjectWithSemantic& operator=( ObjectWithSemantic&& other ) {
42  CORE_UNUSED( other );
43  CORE_ASSERT( m_names == other.m_names, "Try to assign object with different semantics" );
44  return *this;
45  }
46 
47  inline bool shareSemantic( const ObjectWithSemantic& other ) const {
48  return std::any_of( m_names.begin(), m_names.end(), [&other]( const auto& s ) {
49  return other.hasSemantic( s );
50  } );
51  }
52 
53  inline bool sameSemantics( const ObjectWithSemantic& other ) const {
54  return m_names == other.m_names;
55  }
56 
57  protected:
58  template <class... SemanticNames>
59  inline explicit ObjectWithSemantic( SemanticNames... names ) : m_names { names... } {}
60 
61  inline explicit ObjectWithSemantic( const SemanticNameCollection& otherNames ) :
62  m_names { otherNames } {}
63 
64  private:
65  SemanticNameCollection m_names;
66 };
67 
68 } // namespace Utils
69 } // namespace Core
70 } // namespace Ra
Object associated with one or multiple semantic names.
std::set< SemanticName > SemanticNameCollection
Store in set to allow for logarithmic search.
Definition: Cage.cpp:3