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

#include <observable.h>

Inheritance diagram for UTIL::DETAIL::OBSERVABLE_BASE:
UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER > UTIL::OBSERVABLE< ObserverInterface > KIGFX::GAL_DISPLAY_OPTIONS

Classes

struct  IMPL
 

Public Member Functions

 OBSERVABLE_BASE ()
 
 OBSERVABLE_BASE (OBSERVABLE_BASE &other)
 
 ~OBSERVABLE_BASE ()
 
size_t size () const
 

Protected Member Functions

void on_observers_empty ()
 
void enter_iteration ()
 
void leave_iteration ()
 
void add_observer (void *observer)
 
void remove_observer (void *observer)
 

Protected Attributes

std::shared_ptr< IMPLimpl_
 

Private Member Functions

void allocate_impl ()
 
void allocate_shared_impl ()
 
void deallocate_impl ()
 
std::shared_ptr< IMPLget_shared_impl ()
 

Friends

class UTIL::LINK
 

Detailed Description

Definition at line 44 of file observable.h.

Constructor & Destructor Documentation

UTIL::DETAIL::OBSERVABLE_BASE::OBSERVABLE_BASE ( )

Definition at line 172 of file observable.cpp.

173  {
174  }
UTIL::DETAIL::OBSERVABLE_BASE::OBSERVABLE_BASE ( OBSERVABLE_BASE other)

Definition at line 177 of file observable.cpp.

178  : impl_( other.get_shared_impl() )
179  {
180  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
UTIL::DETAIL::OBSERVABLE_BASE::~OBSERVABLE_BASE ( )

Definition at line 183 of file observable.cpp.

184  {
185  }

Member Function Documentation

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

Definition at line 216 of file observable.cpp.

References allocate_impl(), and impl_.

217  {
218  allocate_impl();
219  impl_->add_observer( observer );
220  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
void UTIL::DETAIL::OBSERVABLE_BASE::allocate_impl ( )
private

Definition at line 188 of file observable.cpp.

References impl_.

Referenced by add_observer().

189  {
190  if(!impl_)
191  impl_ = std::make_shared<IMPL>( this );
192  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
void UTIL::DETAIL::OBSERVABLE_BASE::allocate_shared_impl ( )
private

Definition at line 195 of file observable.cpp.

References impl_.

Referenced by get_shared_impl().

196  {
197  if(!impl_)
198  impl_ = std::make_shared<IMPL>();
199  else
200  impl_->set_shared();
201  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
void UTIL::DETAIL::OBSERVABLE_BASE::deallocate_impl ( )
private

Definition at line 204 of file observable.cpp.

References impl_.

Referenced by on_observers_empty().

204  {
205  impl_.reset();
206  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
void UTIL::DETAIL::OBSERVABLE_BASE::enter_iteration ( )
protected

Definition at line 230 of file observable.cpp.

References impl_.

Referenced by UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::Notify(), and UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::NotifyIgnore().

231  {
232  if( impl_ )
233  impl_->enter_iteration();
234  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
std::shared_ptr< OBSERVABLE_BASE::IMPL > UTIL::DETAIL::OBSERVABLE_BASE::get_shared_impl ( )
private

Definition at line 209 of file observable.cpp.

References allocate_shared_impl(), and impl_.

210  {
212  return impl_;
213  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
void UTIL::DETAIL::OBSERVABLE_BASE::leave_iteration ( )
protected

Definition at line 237 of file observable.cpp.

References impl_.

Referenced by UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::Notify(), and UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::NotifyIgnore().

238  {
239  if( impl_)
240  {
241  impl_->leave_iteration();
242 
243  if( !impl_->is_iterating() && !impl_->is_shared() && impl_.use_count() == 1 )
244  impl_.reset();
245  }
246  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
void UTIL::DETAIL::OBSERVABLE_BASE::on_observers_empty ( )
protected

Definition at line 258 of file observable.cpp.

References deallocate_impl().

259  {
260  // called by an impl that is owned by this, ie. it is a non-shared impl
261  // also it is not iterating
262  deallocate_impl();
263  }
void UTIL::DETAIL::OBSERVABLE_BASE::remove_observer ( void *  observer)
protected

Definition at line 223 of file observable.cpp.

References impl_.

224  {
225  assert( impl_ );
226  impl_->remove_observer( observer );
227  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93
size_t UTIL::DETAIL::OBSERVABLE_BASE::size ( ) const

Definition at line 249 of file observable.cpp.

References impl_.

250  {
251  if( impl_ )
252  return impl_->observers_.size();
253  else
254  return 0;
255  }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93

Friends And Related Function Documentation

friend class UTIL::LINK
friend

Definition at line 54 of file observable.h.

Member Data Documentation


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