Follow this link to skip to the main content

Function_Piecewise< Targ, Tval > Class Template Reference

#include <function_piecewise.h>

Inheritance diagram for Function_Piecewise< Targ, Tval >:

Inheritance graph
[legend]
Collaboration diagram for Function_Piecewise< Targ, Tval >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Function_Piecewise ()
virtual ~Function_Piecewise ()
virtual Tval operator() (Targ)
void append (Function< Targ, Tval > *, Targ)
void modify_domain (DWORD segment, Targ domain_max)
void remove (Function< Targ, Tval > *)
void dealloc_all ()
Targ get_domain_min ()
Targ get_domain_max ()
bool set_domain_min (Targ x_min)
virtual void set_coeffs (Tval *coeffs)
virtual void set_coeffs (Tval *coeffs)
virtual void set_domain_offset (Targ offset)
virtual void set_domain_offset (Targ offset)

Protected Attributes

vector< Function< Targ, Tval > * > _function_list
vector< Targ > _argument_map
Targ _domain_min
Targ _domain_max

Detailed Description

template<class Targ = double, class Tval = double>
class Function_Piecewise< Targ, Tval >

This class allows the composition where each element can be any type of function (derived from Function base class)

Definition at line 60 of file function_piecewise.h.


Constructor & Destructor Documentation

template<class Targ, class Tval>
Function_Piecewise< Targ, Tval >::Function_Piecewise (  ) 

Definition at line 109 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_argument_map, Function_Piecewise< Targ, Tval >::_domain_max, and Function_Piecewise< Targ, Tval >::_domain_min.

00110 {
00111   _domain_min = 0.0;
00112   _domain_max = 0.0;
00113   // set the first element of the _argument_map vector:
00114   _argument_map.push_back(_domain_min); // hard-wire the domain minimum for now 
00115 
00116 }

template<class Targ, class Tval>
Function_Piecewise< Targ, Tval >::~Function_Piecewise (  )  [virtual]

Definition at line 122 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_argument_map, and Function_Piecewise< Targ, Tval >::_function_list.

00123 {
00124   // don't do this because the pointers may be to static memory.
00125   // Call dealloc_all() to do deep deallocation.
00126   //  for(DWORD i = 0; i < _function_list.size(); i++) 
00127   //    delete _function_list[i];
00128 
00129   // but we can delete the vectors we allocated. These are vectors of pointers, so
00130   // it's okay.
00131   _function_list.clear();
00132   _argument_map.clear();
00133 }


Member Function Documentation

template<class Targ, class Tval>
Tval Function_Piecewise< Targ, Tval >::operator() ( Targ   )  [virtual]

Implements Function< Targ, Tval >.

Definition at line 153 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_argument_map, and Function_Piecewise< Targ, Tval >::_function_list.

00154 {
00155   Tval null_return = 0; // assuming that complex types can init to zero themselves
00156   if(x < _argument_map[0]) {
00157     cerr << "Function::operator(): argument " << x << endl;
00158     cerr << "                      is less than valid range: " << _argument_map[0] << endl;
00159     return null_return;
00160   }
00161 
00162   for(DWORD i = 0; i < _argument_map.size()-1; i++) {
00163     if(x >= _argument_map[i] && x <= _argument_map[i+1]) {
00164       return (*_function_list[i])(x);
00165     }
00166   }
00167 
00168   // if we got here, then the x is outside of the valid range of this composition:
00169   printf("Function::operator(): argument %12f\n", x);
00170   printf("is greater than valid range %12f\n", _argument_map[_argument_map.size()-1]);
00171   return null_return;
00172 }

template<class Targ, class Tval>
void Function_Piecewise< Targ, Tval >::append ( Function< Targ, Tval > *  ,
Targ   
)

Definition at line 178 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_argument_map, Function_Piecewise< Targ, Tval >::_domain_max, and Function_Piecewise< Targ, Tval >::_function_list.

00180 {
00181   _function_list.push_back(fn_element);
00182   _domain_max += duration;
00183   _argument_map.push_back(_domain_max);
00184   cout << "appending function, now domain max is " << _domain_max << endl;
00185 }

template<class Targ, class Tval>
void Function_Piecewise< Targ, Tval >::modify_domain ( DWORD  segment,
Targ  domain_max 
)

Definition at line 200 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_argument_map.

00201 {
00202   // update the domain:
00203   double delta = duration - (_argument_map[segment+1] - _argument_map[segment]);
00204   // update all following segments' boundaries here:
00205   for(DWORD i = segment+1; i < _argument_map.size(); i++)
00206     _argument_map[i] += delta;
00207 }

template<class Targ, class Tval>
void Function_Piecewise< Targ, Tval >::remove ( Function< Targ, Tval > *   ) 

Definition at line 191 of file function_piecewise.h.

00192 {
00193   cout << "ERROR: Currently not supporting selective removal of function elements!" << endl;
00194 }

template<class Targ, class Tval>
void Function_Piecewise< Targ, Tval >::dealloc_all (  ) 

Definition at line 142 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_function_list.

00143 {
00144   for(DWORD i = 0; i < _function_list.size(); i++) 
00145     delete _function_list[i];
00146 }

template<class Targ = double, class Tval = double>
Targ Function_Piecewise< Targ, Tval >::get_domain_min (  )  [inline]

Definition at line 77 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_argument_map.

00077 {return _argument_map[0];}

template<class Targ = double, class Tval = double>
Targ Function_Piecewise< Targ, Tval >::get_domain_max (  )  [inline]

Definition at line 78 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_argument_map.

00078 {return _argument_map[_argument_map.size()-1];}

template<class Targ, class Tval>
bool Function_Piecewise< Targ, Tval >::set_domain_min ( Targ  x_min  ) 

Definition at line 213 of file function_piecewise.h.

References Function_Piecewise< Targ, Tval >::_argument_map, Function_Piecewise< Targ, Tval >::_domain_max, and Function_Piecewise< Targ, Tval >::_domain_min.

00214 {
00215   if(_argument_map.size() > 1) {
00216     if(_argument_map[1] <= x_min) {
00217       // we can't move _domain_min greater than the start of the second
00218       // element in the piece-wise function
00219       cerr << "ERROR: Attempting to move domain minimum past the domain interval of the first piecewise element!\n";
00220       return false;
00221     }
00222   }
00223   else // don't have any elements yet, keep domain max equal to domain min
00224     _domain_max = x_min;
00225     
00226   _domain_min = x_min;
00227   _argument_map[0] = _domain_min;
00228   return true;
00229 }

template<class Targ = double, class Tval = double>
virtual void Function< Targ, Tval >::set_coeffs ( Tval *  coeffs  )  [inline, virtual, inherited]

Reimplemented in Polynomial< Order, Targ, Tval >.

Definition at line 41 of file function.h.

00041 {};

template<class Targ = double, class Tval = double>
virtual void Function< Targ, Tval >::set_coeffs ( Tval *  coeffs  )  [inline, virtual, inherited]

Reimplemented in Polynomial< Order, Targ, Tval >.

Definition at line 45 of file function_piecewise.h.

00045 {};

template<class Targ = double, class Tval = double>
virtual void Function< Targ, Tval >::set_domain_offset ( Targ  offset  )  [inline, virtual, inherited]

Reimplemented in Polynomial< Order, Targ, Tval >, and Function_Sine< Targ, Tval >.

Definition at line 42 of file function.h.

00042 {};

template<class Targ = double, class Tval = double>
virtual void Function< Targ, Tval >::set_domain_offset ( Targ  offset  )  [inline, virtual, inherited]

Reimplemented in Polynomial< Order, Targ, Tval >, and Function_Sine< Targ, Tval >.

Definition at line 46 of file function_piecewise.h.

00046 {};


Member Data Documentation

template<class Targ = double, class Tval = double>
vector<Function<Targ, Tval>*> Function_Piecewise< Targ, Tval >::_function_list [protected]

Composition of the functions, used for defining piecewise functions. This member is used only if the there are more than one pieces in this composition. External access to this member will be allowed only to the function generator classes that will be declared as friends of this class, direct access will be allowed for efficiency. composition of the functions

Definition at line 90 of file function_piecewise.h.

Referenced by Function_Piecewise< Targ, Tval >::append(), Function_Piecewise< Targ, Tval >::dealloc_all(), Function_Piecewise< Targ, Tval >::operator()(), and Function_Piecewise< Targ, Tval >::~Function_Piecewise().

template<class Targ = double, class Tval = double>
vector<Targ> Function_Piecewise< Targ, Tval >::_argument_map [protected]

Definition the active range of each element of the composition. The index of the _function_list element to use can be looked-up by the argument value. An ordering is assumed on the Targ type. The index into this vector corresponds to the index of the desired element in _function_list.

Definition at line 99 of file function_piecewise.h.

Referenced by Function_Piecewise< Targ, Tval >::append(), Function_Piecewise< Targ, Tval >::Function_Piecewise(), Function_Piecewise< Targ, Tval >::get_domain_max(), Function_Piecewise< Targ, Tval >::get_domain_min(), Function_Piecewise< Targ, Tval >::modify_domain(), Function_Piecewise< Targ, Tval >::operator()(), Function_Piecewise< Targ, Tval >::set_domain_min(), and Function_Piecewise< Targ, Tval >::~Function_Piecewise().

template<class Targ = double, class Tval = double>
Targ Function_Piecewise< Targ, Tval >::_domain_min [protected]

template<class Targ = double, class Tval = double>
Targ Function_Piecewise< Targ, Tval >::_domain_max [protected]


The documentation for this class was generated from the following file: