Dali 3D User Interface Engine
property-constraint.h
Go to the documentation of this file.
1 #ifndef __DALI_PROPERTY_CONSTRAINT_H__
2 #define __DALI_PROPERTY_CONSTRAINT_H__
3 
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20 
21 // INTERNAL INCLUDES
28 
29 namespace Dali
30 {
31 
32 namespace Internal
33 {
34 
38 template < typename PropertyType >
40 {
41 public:
42 
43  typedef std::vector < PropertyInputAccessor > InputContainer;
44  typedef typename InputContainer::iterator InputContainerIter;
45  typedef typename InputContainer::const_iterator InputContainerConstIter;
46 
47  typedef std::vector< PropertyInputIndexer< PropertyInputAccessor > > InputIndexerContainer;
48 
50 
57  : mInputsInitialized( false ),
58  mFunction( func ),
59  mInputs()
60  {
61  }
62 
69  const InputContainer& inputs )
70  : mInputsInitialized( false ),
71  mFunction( func ),
72  mInputs( inputs )
73  {
74  }
75 
80  {
81  delete mFunction;
82  }
83 
92  {
93  return new PropertyConstraint< PropertyType >( reinterpret_cast< ConstraintFunction* >( mFunction->Clone() ), mInputs );
94  }
95 
101  void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
102  {
103  if ( index >= mInputs.size() )
104  {
105  mInputs.push_back( PropertyInputAccessor() );
106  }
107 
108  mInputs[ index ].SetInput( input, componentIndex );
109  }
110 
116  const PropertyInputImpl* GetInput( unsigned int index ) const
117  {
118  if ( index < mInputs.size() )
119  {
120  return mInputs[ index ].GetInput();
121  }
122 
123  return NULL;
124  }
125 
131  {
132  if ( !mInputsInitialized )
133  {
134  // Check whether the inputs are initialized yet
135  unsigned int index( 0u );
136  for ( const PropertyInputImpl* input = GetInput( index );
137  NULL != input;
138  input = GetInput( ++index ) )
139  {
140  if ( !input->InputInitialized() )
141  {
142  return false;
143  }
144  }
145 
146  // All inputs are now initialized
147  mInputsInitialized = true;
148  }
149 
150  return true;
151  }
152 
158  {
159  unsigned int index( 0u );
160  for ( const PropertyInputImpl* input = GetInput( index );
161  NULL != input;
162  input = GetInput( ++index ) )
163  {
164  if ( input->InputChanged() )
165  {
166  // At least one of the inputs has changed
167  return true;
168  }
169  }
170 
171  return false;
172  }
173 
179  void Apply( BufferIndex bufferIndex, PropertyType& current )
180  {
181  InputIndexerContainer mInputIndices;
182  PropertyInputContainer mIndices;
183  const unsigned int noOfInputs = mInputs.size();
184 
185  mInputIndices.reserve( noOfInputs );
186  mIndices.Reserve( noOfInputs );
187 
188  const InputContainerConstIter endIter = mInputs.end();
189  unsigned int index = 0;
190  for ( InputContainerConstIter iter = mInputs.begin(); iter != endIter; ++iter, ++index )
191  {
192  DALI_ASSERT_DEBUG( NULL != iter->GetInput() );
193  mInputIndices.push_back( PropertyInputIndexer< PropertyInputAccessor >( bufferIndex, &*iter ) );
194  mIndices.PushBack( &mInputIndices[ index ] );
195  }
196 
197  CallbackBase::Execute< PropertyType&, const PropertyInputContainer& >( *mFunction, current, mIndices );
198  }
199 
200 private:
201 
202  // Undefined
204 
205  // Undefined
207 
208 private:
209 
211 
213 
215 };
216 
217 } // namespace Internal
218 
219 } // namespace Dali
220 
221 #endif // __DALI_PROPERTY_CONSTRAINT_H__
Dali Docs Home
Read more about Dali