00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef VEE_OPERATOR_RANDOM_TMPL_H
00021 #define VEE_OPERATOR_RANDOM_TMPL_H
00022
00023 #include <vee_operator_random.h>
00024
00025 #include <vee_random.h>
00026
00027
00028
00029 template <>
00030 void VEE_OperatorRandomSelect<float>::deliver(VEE_Object *o, const float & v)
00031 {
00032 o->setValueFloat(m_id.c_str(), v);
00033 }
00034
00035 template <>
00036 void VEE_OperatorRandomSelect<int>::deliver(VEE_Object *o, const int & v)
00037 {
00038 o->setValueInt(m_id.c_str(), v);
00039 }
00040
00041 template <>
00042 void VEE_OperatorRandomSelect<VEE_Vector3>::deliver
00043 (VEE_Object *o, const VEE_Vector3 & v)
00044 {
00045 o->setValueVector3(m_id.c_str(), v);
00046 }
00047
00048 template <>
00049 void VEE_OperatorRandomSelect<VEE_Matrix3>::deliver
00050 (VEE_Object *o, const VEE_Matrix3 & v)
00051 {
00052 o->setValueMatrix3(m_id.c_str(), v);
00053 }
00054
00057
00058 template <class T>
00059 VEE_OperatorRandomSelect<T>::VEE_OperatorRandomSelect()
00060 {}
00061
00062 template <class T>
00063 VEE_OperatorRandomSelect<T>::~VEE_OperatorRandomSelect()
00064 {}
00065
00066 template <class T>
00067 void VEE_OperatorRandomSelect<T>::operate(VEE_Object *o, float)
00068 {
00069 uint range = m_values.size();
00070
00071 if(!range) return;
00072
00073 float rand = VEE_rand.rand0X(range);
00074 const T & value = m_values[((uint) rand) % range];
00075 deliver(o, value);
00076 }
00077
00078 template <class T>
00079 VEE_Operator * VEE_OperatorRandomSelect<T>::clone() const
00080 {
00081 return new VEE_OperatorRandomSelect(*this);
00082 }
00083
00086 template <class T>
00087 void VEE_OperatorRandomSelect<T>::addValue(T v)
00088 {
00089 if(find(v) < 0)
00090 m_values.push_back(v);
00091 }
00092
00093 template <class T>
00094 bool VEE_OperatorRandomSelect<T>::removeValue(T v)
00095 {
00096 int i = find(v);
00097 if(i >= 0) {
00098 m_values.erase(m_values.begin() + i);
00099 return true;
00100 }
00101 return false;
00102 }
00103
00107 template <class T>
00108 int VEE_OperatorRandomSelect<T>::find(T v)
00109 {
00110 typename std::vector<T>::iterator it =
00111 std::find(m_values.begin(), m_values.end(), v);
00112
00113 if(it == m_values.end())
00114 return -1;
00115
00116 return it - m_values.begin();
00117 }
00118
00119
00120 #endif