- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# FCDocument/FCDParameterAnimatable.hpp

    00001 /*
    00002     Copyright (C) 2005-2007 Feeling Software Inc.
    00003     Portions of the code are:
    00004     Copyright (C) 2005-2007 Sony Computer Entertainment America
    00005
    00006     MIT License: http://www.opensource.org/licenses/mit-license.php
    00007 */
    00008
    00009 #ifndef _FCD_ANIMATED_H_
    00010 #include "FCDocument/FCDAnimated.h"
    00011 #endif // _FCD_ANIMATED_H_
    00012
    00013 //
    00014 // FCDParameterAnimatableT
    00015 //
    00016
    00017 template <class TYPE, int QUALIFIERS>
    00018 FCDParameterAnimatableT<TYPE, QUALIFIERS>::FCDParameterAnimatableT(FUParameterizable* _parent)
    00019 :   FCDParameterAnimatable(_parent)
    00020 {
    00021 }
    00022
    00023 template <class TYPE, int QUALIFIERS>
    00024 FCDParameterAnimatableT<TYPE, QUALIFIERS>::FCDParameterAnimatableT(FUParameterizable* _parent, const TYPE& defaultValue)
    00025 :   FCDParameterAnimatable(_parent)
    00026 ,   value(defaultValue)
    00027 {
    00028 }
    00029
    00030 template <class TYPE, int QUALIFIERS>
    00031 FCDParameterAnimatableT<TYPE, QUALIFIERS>::~FCDParameterAnimatableT()
    00032 {
    00033 }
    00034
    00035 template <class TYPE, int QUALIFIERS>
    00036 FCDParameterAnimatableT<TYPE, QUALIFIERS>& FCDParameterAnimatableT<TYPE, QUALIFIERS>::operator= (const TYPE& copy)
    00037 {
    00038     value = copy;
    00039     GetParent()->SetValueChange();
    00040     return *this;
    00041 }
    00042
    00043 //
    00044 // FCDParameterListAnimatableT
    00045 //
    00046
    00047 template <class TYPE, int QUALIFIERS>
    00048 FCDParameterListAnimatableT<TYPE, QUALIFIERS>::FCDParameterListAnimatableT(FUParameterizable* parent)
    00049 :   FCDParameterListAnimatable(parent)
    00050 {
    00051 }
    00052
    00053 template <class TYPE, int QUALIFIERS>
    00054 FCDParameterListAnimatableT<TYPE, QUALIFIERS>::~FCDParameterListAnimatableT()
    00055 {
    00056 }
    00057
    00058 template <class TYPE, int QUALIFIERS>
    00059 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::set(size_t index, const TYPE& value)
    00060 {
    00061     values.at(index) = value;
    00062     GetParent()->SetValueChange();
    00063 }
    00064
    00065 template <class TYPE, int QUALIFIERS>
    00066 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::insert(size_t index, const TYPE& value)
    00067 {
    00068     values.insert(values.begin() + index, value);
    00069     GetParent()->SetStructureChangedFlag();
    00070     GetParent()->SetDirtyFlag();
    00071     OnInsertion(index, 1);
    00072     OnPotentialSizeChange();
    00073 }
    00074
    00075 template <class TYPE, int QUALIFIERS>
    00076 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::insert(size_t index, const TYPE* _values, size_t count)
    00077 {
    00078     values.insert(values.begin() + index, _values, count);
    00079     GetParent()->SetStructureChangedFlag();
    00080     GetParent()->SetDirtyFlag();
    00081     OnInsertion(index, count);
    00082     OnPotentialSizeChange();
    00083 }
    00084
    00085 template <class TYPE, int QUALIFIERS>
    00086 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::insert(size_t index, size_t count, const TYPE& value)
    00087 {
    00088     values.insert(values.begin() + index, count, value);
    00089     GetParent()->SetStructureChangedFlag();
    00090     GetParent()->SetDirtyFlag();
    00091     OnInsertion(index, count);
    00092     OnPotentialSizeChange();
    00093 }
    00094
    00095 template <class TYPE, int QUALIFIERS>
    00096 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::erase(size_t index)
    00097 {
    00098     values.erase(index);
    00099     GetParent()->SetStructureChangedFlag();
    00100     GetParent()->SetDirtyFlag();
    00101     OnRemoval(index, 1);
    00102     OnPotentialSizeChange();
    00103 }
    00104
    00105 template <class TYPE, int QUALIFIERS>
    00106 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::erase(const TYPE& value)
    00107 {
    00108     size_t index = find(value);
    00109     if (index < values.size()) erase(index);
    00110     OnPotentialSizeChange();
    00111 }
    00112
    00113 template <class TYPE, int QUALIFIERS>
    00114 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::erase(size_t start, size_t end)
    00115 {
    00116     values.erase(values.begin() + start, values.begin() + end);
    00117     GetParent()->SetStructureChangedFlag();
    00118     GetParent()->SetDirtyFlag();
    00119     OnRemoval(start, end - start);
    00120     OnPotentialSizeChange();
    00121 }
    00122
    00123 template <class TYPE, int QUALIFIERS>
    00124 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::clear()
    00125 {
    00126     OnRemoval(0, values.size());
    00127     values.clear();
    00128     GetParent()->SetStructureChangedFlag();
    00129     GetParent()->SetDirtyFlag();
    00130     OnPotentialSizeChange();
    00131 }
    00132
    00133 template <class TYPE, int QUALIFIERS>
    00134 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::push_back(const TYPE& value)
    00135 {
    00136     OnInsertion(values.size(), 1);
    00137     values.push_back(value);
    00138     GetParent()->SetStructureChangedFlag();
    00139     GetParent()->SetDirtyFlag();
    00140     OnPotentialSizeChange();
    00141 }
    00142
    00143 template <class TYPE, int QUALIFIERS>
    00144 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::push_front(const TYPE& value)
    00145 {
    00146     values.push_front(value);
    00147     GetParent()->SetStructureChangedFlag();
    00148     GetParent()->SetDirtyFlag();
    00149     OnInsertion(0, 1);
    00150     OnPotentialSizeChange();
    00151 }
    00152
    00153 template <class TYPE, int QUALIFIERS>
    00154 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::pop_back()
    00155 {
    00156     OnRemoval(size() - 1, 1);
    00157     values.pop_back();
    00158     GetParent()->SetStructureChangedFlag();
    00159     GetParent()->SetDirtyFlag();
    00160     OnPotentialSizeChange();
    00161 }
    00162
    00163 template <class TYPE, int QUALIFIERS>
    00164 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::pop_front()
    00165 {
    00166     values.pop_front();
    00167     GetParent()->SetStructureChangedFlag();
    00168     GetParent()->SetDirtyFlag();
    00169     OnRemoval(0, 1);
    00170     OnPotentialSizeChange();
    00171 }
    00172
    00173 template <class TYPE, int QUALIFIERS>
    00174 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::resize(size_t count)
    00175 {
    00176     if (count > values.size()) OnInsertion(values.size(), count - values.size());
    00177     else if (count < values.size()) OnRemoval(count, values.size() - count);
    00178     values.resize(count);
    00179     OnPotentialSizeChange();
    00180 }
    00181
    00182 template <class TYPE, int QUALIFIERS>
    00183 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::resize(size_t count, const TYPE& value)
    00184 {
    00185     if (count > values.size()) OnInsertion(values.size(), count - values.size());
    00186     else if (count < values.size()) OnRemoval(count - values.size(), values.size());
    00187     values.resize(count, value);
    00188     OnPotentialSizeChange();
    00189 }
    00190
    00191 template <class TYPE, int QUALIFIERS>
    00192 void FCDParameterListAnimatableT<TYPE, QUALIFIERS>::OnPotentialSizeChange()
    00193 {
    00194     size_t animatedCount = animateds.size();
    00195     if (animatedCount == 0) return;
    00196
    00197     // Check if the first FCDAnimated points to the correct values.
    00198     // If it does, then they all should be fine.
    00199     FCDAnimated* animated = animateds.front();
    00200     FUAssert((size_t) animated->GetArrayElement() < values.size(), return);
    00201     if (animated->GetValue(0) == (void*) &values[animated->GetArrayElement()]) return;
    00202
    00203     // Process all the animateds and set their value pointers.
    00204     // IMPORTANT: it is assumed that these values are FLOATS and ORDERED.
    00205     size_t stride = animated->GetValueCount();
    00206     for (size_t i = 0; i < animatedCount; ++i)
    00207     {
    00208         animated = animateds[i];
    00209         size_t arrayElement = animated->GetArrayElement();
    00210         FUAssert(arrayElement < values.size(), return);
    00211         for (size_t j = 0; j < stride; ++j)
    00212         {
    00213             animated->SetValue(j, (float*) (j * sizeof(float) + ((char*) &values[arrayElement])));
    00214         }
    00215     }
    00216 }
    00217