ComponentAttr.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 //=================================== ComponentAttr_Index =========================================================
5 template< class Component >
7  cm( inst, this, "ComponentAttr_Index" ),
8  inst( inst ),
9  iterating( false )
10 {
11 }
12 
13 template< class Component >
15 {
16  return this->inst;
17 }
18 
19 template< class Component >
21 {
22  switch( event )
23  {
25  {
26  if( this->iterating )
27  this->cm.warning( SRC_INFO, "Should not add listeners when iterating over them." );
28  this->listeners.insert( std::pair( attr, listener ) );
29  } break;
30 
32  {
33  if( this->iterating )
34  this->cm.warning( SRC_INFO, "Should not remove listeners when iterating over them." );
35 
36  auto range = this->listeners.equal_range( attr );
37  for( auto it = range.first; it != range.second; ++it )
38  if( it->second == listener )
39  {
40  this->listeners.erase( it );
41  break;
42  }
43  } break;
44 
46  {
47  this->iterating += 1;
48  auto range = this->listeners.equal_range( attr );
49  for( auto it = range.first; it != range.second; ++it )
50  it->second->Attribute_Changed( attr );
51  this->iterating -= 1;
52 
53  this->Component_AttrChanged( component, attr );
54  } break;
55 
57  {
58  } break;
59 
61  {
62  this->iterating += 1;
63  auto range = this->listeners.equal_range( attr );
64  for( auto it = range.first; it != range.second; ++it )
65  it->second->Attribute_Deactivated( attr );
66  this->iterating -= 1;
67  } break;
68  }
69 }
70 
71 //=================================== ComponentAttr =========================================================
72 template< class Component, class T >
75  iv::SharedAttr_I< T >( cm, this, initial_value ),
76  component( nullptr ),
77  index( nullptr )
78 {
79 }
80 
81 template< class Component, class T >
83 {
84  this->Index();
85 }
86 
87 template< class Component, class T >
90  iv::SharedAttr_I< T >( src.owner(), this, src.Get() ),
91  component( nullptr ),
92  index( nullptr )
93 {
94 }
95 
96 template< class Component, class T >
98 {
99  this->Modify( src.owner(), src.Get() );
100 }
101 
102 template< class Component, class T >
104 {
105  if( bool( index ) == bool( this->index ) )
106  return;
107 
108  if( !index )
109  this->Notify_Deactivated();
110 
111  this->component = component;
112  this->index = index;
113 
114  if( index )
115  this->Notify_Activated();
116 }
117 
118 template< class Component, class T >
120 {
121  this->Index( nullptr, nullptr );
122 }
123 
124 template< class Component, class T >
126 {
127  if( !this->index )
128  {
130  this->owner()->warning( SRC_INFO, "Event ", event, " on ComponentAttr can not be served because it is not currently registered to an Index." );
131  return;
132  }
133 
134  this->index->AttributeEvent( event, this->component, attr, listener );
135 }
136 
137 }