Field.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 //=========================== Field ==================================
5 template< class T >
7  FieldI(),
9  cm( inst, this, "Field_R" ),
10  inst( inst ),
11  source_r( nullptr ),
12  source_rw( nullptr )
13 {
14 }
15 
16 template< class T >
18 {
19  if( this->source_r )
20  this->source_r->Remove_Listener( this );
21 }
22 
23 template< class T >
25 {
26  return this->inst;
27 }
28 
29 template< class T >
31 {
32  if( this->source_r )
33  this->source_r->Remove_Listener( this );
34 
35  this->constant = {};
36  this->source_r = src;
37  this->source_rw = nullptr;
38 
39  if( this->source_r )
40  this->source_r->Insert_Listener( this );
41 
42  this->OnChanged( false );
43 }
44 
45 template< class T >
47 {
48  if( this->source_r )
49  this->source_r->Remove_Listener( this );
50 
51  this->source_r = nullptr;
52  this->source_rw = nullptr;
53  this->constant = {};
54 
55  this->OnChanged( false );
56 }
57 
58 template< class T >
59 void Field< T >::Assign_Constant( T const & value )
60 {
61  if( this->constant == value )
62  return;
63 
64  if( this->source_r )
65  this->source_r->Remove_Listener( this );
66 
67  this->source_r = nullptr;
68  this->source_rw = nullptr;
69  this->constant = value;
70 
71  this->OnChanged( false );
72 }
73 
74 template< class T >
75 T Field< T >::Get() const
76 {
77  if( this->constant.has_value() )
78  return this->constant.value();
79 
80  if( !this->source_r )
81  return T();
82 
83  auto result = this->source_r->Get();
84  return result;
85 }
86 
87 template< class T >
89 {
90  this->OnChanged( true );
91 }
92 
93 template< class T >
94 void Field< T >::Attribute_Deactivated( Attribute * src )
95 {
96  this->source_r = nullptr;
97  this->source_rw = nullptr;
98  this->OnChanged( false );
99 }
100 
101 template< class T >
102 void Field< T >::AnySource_R_Impl( Attribute * src )
103 {
104  Attr< T > * casted = dynamic_cast< Attr< T > * >( src );
105  if( casted )
106  this->Assign_Attribute_R( casted );
107 }
108 
109 template< class T >
110 std::type_index Field< T >::Type_Impl()
111 {
112  return typeid( T );
113 }
114 
115 template< class T >
116 Attribute::ValueMode Field< T >::mode_Impl() const
117 {
118  if( this->source_rw )
119  {
120  return this->source_rw->Mode();
121  }
122  else if( this->source_r )
123  {
124  auto src_mode = this->source_r->Mode();
125  if( src_mode == Attribute::ValueMode::Disabled )
126  return Attribute::ValueMode::Disabled;
127  else
128  return Attribute::ValueMode::Value;
129  }
130  else if( this->constant.has_value() )
131  {
132  return Attribute::ValueMode::Value;
133  }
134  else
135  {
136  return Attribute::ValueMode::Disabled;
137  }
138 }
139 
140 template< class T >
141 FieldI::Assignment Field< T >::AssignmentState_impl() const
142 {
143  if( this->source_rw )
144  return Assignment::Attribute_RW;
145  else if( this->source_r )
146  return Assignment::Attribute_R;
147  else if( this->constant.has_value() )
148  return Assignment::Constant;
149  else
150  return Assignment::Unassigned;
151 }
152 
153 template< class T >
155 {
156  if( this->source_r )
157  this->source_r->Remove_Listener( this );
158 
159  this->constant = {};
160  this->source_r = attr;
161  this->source_rw = attr;
162 
163  if( this->source_r )
164  this->source_r->Insert_Listener( this );
165 
166  this->OnChanged( false );
167 }
168 
169 template< class T >
170 void Field< T >::Modify( T const & val )
171 {
172  if( this->source_rw )
173  this->source_rw->Modify( &this->cm, val );
174 }
175 
176 template< class T >
178 {
179  Attr< T > * casted = dynamic_cast< Attr< T > * >( src );
180  if( casted )
181  this->Assign_Attribute_RW( casted );
182 }
183 
184 }