source: flair-dev/trunk/include/FlairSimulator/DiscreteTimeVariable.h@ 8

Last change on this file since 8 was 8, checked in by Sanahuja Guillaume, 8 years ago

simulator

File size: 1.2 KB
Line 
1// created: 2014/03/30
2// filename: DiscreteTimeVariable.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: base class for discrete time variable
10//
11/*********************************************************************/
12
13#ifndef DISCRETETIMEVARIABLE_H
14#define DISCRETETIMEVARIABLE_H
15
16#include <stdlib.h>
17
18namespace flair
19{
20namespace simulator
21{
22 template <typename T,size_t size>
23 class DiscreteTimeVariable
24 {
25 public:
26 DiscreteTimeVariable(){};
27 ~DiscreteTimeVariable(){};
28 T& operator[](ssize_t idx)
29 {
30 if(idx>0) idx=0;
31 if(idx<(ssize_t)(-size+1)) idx=-size+1;
32 return array[-idx];
33 }
34 const T&operator[](ssize_t idx) const
35 {
36 return const_cast<T&>(*this)[idx];
37 };
38 void Update(void)
39 {
40 for(int i=size-1;i>0;i--)
41 {
42 array[i]=array[i-1];
43 }
44 }
45
46 private:
47 T array[size];
48
49 };
50} // end namespace simulator
51} // end namespace flair
52#endif // DISCRETETIMEVARIABLE_H
Note: See TracBrowser for help on using the repository browser.