Page MenuHomec4science

observer.hpp
No OneTemporary

File Metadata

Created
Sat, Nov 16, 18:43

observer.hpp

#ifndef __OBSERVER_HPP__
#define __OBSERVER_HPP__
#include <iterator>
#include <vector>
#include <algorithm>
//#include "Vector.h"
//#include <boost/numeric/ublas/vector.hpp>
typedef std::vector<double> state_type;
//typedef boost::numeric::ublas::vector<double> state_type;
class KeepLast{
protected:
state_type last;
double time;
public:
KeepLast(){}
KeepLast(state_type x):last(x){}
void operator()(const state_type& x, double t);
void resize(uint n){last.resize(n);}
void init(uint n){last.resize(n);}
state_type& getState(){return last;}
double getTime(){return time;}
void setTime(double t){time=t;}
};
struct push_back_state_and_time
{
std::vector< state_type >& m_states;
std::vector< double >& m_times;
push_back_state_and_time( std::vector< state_type > &states , std::vector< double > &times )
: m_states( states ) , m_times( times ) { }
void operator()( const state_type &x , double t )
{m_states.push_back( x );m_times.push_back( t );}
state_type& getState(){return m_states.back();}
};
struct push_back_sel_state_and_time: push_back_state_and_time{
std::vector<uint>& m_idx;
push_back_sel_state_and_time( std::vector< state_type > &states , std::vector< double > &times, std::vector<uint> &idx):
push_back_state_and_time(states,times),m_idx(idx){}
void operator()( const state_type &x , double t )
{
state_type x_sel(m_idx.size());
for(int i=0;i<m_idx.size();i++){
x_sel[i]=x[m_idx[i]];
}
m_states.push_back( x_sel );
m_times.push_back( t );
}
};
#endif

Event Timeline