KiCad PCB EDA Suite
UTIL::DETAIL::OBSERVABLE_BASE::IMPL Struct Reference

Public Member Functions

 IMPL (OBSERVABLE_BASE *owned_by=nullptr)
 
bool is_shared () const
 
void set_shared ()
 
 ~IMPL ()
 
void add_observer (void *observer)
 
void remove_observer (void *observer)
 
void collect ()
 
bool is_iterating () const
 
void enter_iteration ()
 
void leave_iteration ()
 

Public Attributes

std::vector< void * > observers_
 
unsigned int iteration_count_
 
OBSERVABLE_BASEowned_by_
 

Detailed Description

Definition at line 57 of file observable.h.

Constructor & Destructor Documentation

UTIL::DETAIL::OBSERVABLE_BASE::IMPL::IMPL ( OBSERVABLE_BASE owned_by = nullptr)

Definition at line 45 of file observable.cpp.

46  : iteration_count_( 0 ), owned_by_( owned_by )
47  {}
UTIL::DETAIL::OBSERVABLE_BASE::IMPL::~IMPL ( )

Definition at line 62 of file observable.cpp.

63  {
64  }

Member Function Documentation

void UTIL::DETAIL::OBSERVABLE_BASE::IMPL::add_observer ( void *  observer)

Definition at line 88 of file observable.cpp.

89  {
90  assert( !is_iterating() );
91  observers_.push_back( observer );
92  }
std::vector< void * > observers_
Definition: observable.h:73
void UTIL::DETAIL::OBSERVABLE_BASE::IMPL::collect ( )

Definition at line 112 of file observable.cpp.

113  {
114  auto it = std::remove_if( observers_.begin(), observers_.end(), DETAIL::equals<void*>( nullptr ) );
115  observers_.erase( it, observers_.end() );
116  }
std::vector< void * > observers_
Definition: observable.h:73
void UTIL::DETAIL::OBSERVABLE_BASE::IMPL::enter_iteration ( )

Definition at line 67 of file observable.cpp.

68  {
70  }
bool UTIL::DETAIL::OBSERVABLE_BASE::IMPL::is_iterating ( ) const

Definition at line 82 of file observable.cpp.

83  {
84  return iteration_count_ != 0;
85  }
bool UTIL::DETAIL::OBSERVABLE_BASE::IMPL::is_shared ( ) const

Definition at line 50 of file observable.cpp.

51  {
52  return owned_by_ == nullptr;
53  }
void UTIL::DETAIL::OBSERVABLE_BASE::IMPL::leave_iteration ( )

Definition at line 73 of file observable.cpp.

74  {
76 
77  if( iteration_count_ == 0 )
78  collect();
79  }
void UTIL::DETAIL::OBSERVABLE_BASE::IMPL::remove_observer ( void *  observer)

Definition at line 95 of file observable.cpp.

96  {
97  auto it = std::find( observers_.begin(), observers_.end(), observer );
98 
99  if( it == observers_.end() )
100  {
101  assert( false );
102  return;
103  }
104 
105  if( is_iterating() )
106  *it = nullptr;
107  else
108  observers_.erase( it );
109  }
std::vector< void * > observers_
Definition: observable.h:73
void UTIL::DETAIL::OBSERVABLE_BASE::IMPL::set_shared ( )

Definition at line 56 of file observable.cpp.

57  {
58  owned_by_ = nullptr;
59  }

Member Data Documentation

unsigned int UTIL::DETAIL::OBSERVABLE_BASE::IMPL::iteration_count_

Definition at line 74 of file observable.h.

std::vector<void*> UTIL::DETAIL::OBSERVABLE_BASE::IMPL::observers_

Definition at line 73 of file observable.h.

OBSERVABLE_BASE* UTIL::DETAIL::OBSERVABLE_BASE::IMPL::owned_by_

Definition at line 75 of file observable.h.


The documentation for this struct was generated from the following files: