Last change
on this file was 13, checked in by Bayard Gildas, 9 years ago |
formatting script + include reformatted
|
File size:
1.1 KB
|
Line | |
---|
1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2014/03/30
|
---|
6 | // filename: DiscreteTimeVariable.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: base class for discrete time variable
|
---|
14 | //
|
---|
15 | /*********************************************************************/
|
---|
16 |
|
---|
17 | #ifndef DISCRETETIMEVARIABLE_H
|
---|
18 | #define DISCRETETIMEVARIABLE_H
|
---|
19 |
|
---|
20 | #include <stdlib.h>
|
---|
21 |
|
---|
22 | namespace flair {
|
---|
23 | namespace simulator {
|
---|
24 | template <typename T, size_t size> class DiscreteTimeVariable {
|
---|
25 | public:
|
---|
26 | DiscreteTimeVariable(){};
|
---|
27 | ~DiscreteTimeVariable(){};
|
---|
28 | T &operator[](ssize_t idx) {
|
---|
29 | if (idx > 0)
|
---|
30 | idx = 0;
|
---|
31 | if (idx < (ssize_t)(-size + 1))
|
---|
32 | idx = -size + 1;
|
---|
33 | return array[-idx];
|
---|
34 | }
|
---|
35 | const T &operator[](ssize_t idx) const {
|
---|
36 | return const_cast<T &>(*this)[idx];
|
---|
37 | };
|
---|
38 | void Update(void) {
|
---|
39 | for (int i = size - 1; i > 0; i--) {
|
---|
40 | array[i] = array[i - 1];
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | private:
|
---|
45 | T array[size];
|
---|
46 | };
|
---|
47 | } // end namespace simulator
|
---|
48 | } // end namespace flair
|
---|
49 | #endif // DISCRETETIMEVARIABLE_H
|
---|
Note:
See
TracBrowser
for help on using the repository browser.