sub_signal.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * sub_signal.hpp -- Data type for representing a function over an *
3  * interval. *
4  * *
5  * Author: Hosein Attarzadeh (shan2@kth.se) *
6  * *
7  * Purpose: Represents a sb-component of a CT signal. *
8  * *
9  * Usage: This file is included automatically *
10  * *
11  * License: BSD3 *
12  *******************************************************************/
13 
14 #ifndef SUB_SIGNAL_HPP
15 #define SUB_SIGNAL_HPP
16 
21 namespace ForSyDe
22 {
23 
24 using namespace sc_core;
25 
27 typedef double CTTYPE;
28 
30 
39 {
40 public:
41 
42  typedef std::function<CTTYPE(const sc_time&)> functype;
43 
45 
47  sub_signal(const sc_time& st,
48  const sc_time& et,
49  const functype& f)
50  : start_time(st), end_time(et), _f(f) {}
51 
53 
56 
58 
61  )
62  : start_time(get_start_time(ss)), end_time(get_end_time(ss)), _f(get_function(ss)) {}
63 
65 
68  ){
69  start_time = get_start_time(ss);
70  end_time = get_end_time(ss);
71  _f = get_function(ss);
72  return *this;
73  }
74 
76 
80  CTTYPE operator() (const sc_time& valAt) const
81  {
82  if ((valAt>=start_time) && (valAt<end_time))
83  return _f(valAt);
84  else
85  {
86  SC_REPORT_ERROR("Using ForSyDe::CT","Access out of sub-signal range");
87  return -1;
88  }
89  }
90 
92 
94  inline friend sc_time get_start_time(const sub_signal& ss)
95  {
96  return ss.start_time;
97  }
98 
100 
102  inline friend sc_time get_end_time(const sub_signal& ss)
103  {
104  return ss.end_time;
105  }
106 
108 
110  inline friend std::function<CTTYPE(const sc_time&)> get_function(const sub_signal& ss)
111  {
112  return ss._f;
113  }
114 
116 
118  inline friend void set_range(sub_signal& ss, sc_time st, sc_time et)
119  {
120  ss.start_time = st;
121  ss.end_time = et;
122  }
123 
125 
127  inline friend void set_function(sub_signal& ss, const std::function<CTTYPE(const sc_time&)>& f)
128  {
129  ss._f = f;
130  }
131 
132  friend std::ostream& operator<< (std::ostream& os, sub_signal &subSig)
133  {
134  os << "(" << get_start_time(subSig) << ", "
135  << get_end_time(subSig) << ") -> f";
136  return os;
137  }
138 private:
139  sc_time start_time;
140  sc_time end_time;
141  functype _f;
142 };
143 
144 }
145 #endif
sub_signal()
A dummy constructor used for sub-signal definition without initialization.
Definition: sub_signal.hpp:55
The sub-signal type used to construct a CT signal.
Definition: sub_signal.hpp:38
double CTTYPE
Type of the values used in the CT MoC (currently fixed)
Definition: sub_signal.hpp:27
friend void set_range(sub_signal &ss, sc_time st, sc_time et)
A helper function used to set the start and end of the range.
Definition: sub_signal.hpp:118
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
friend sc_time get_end_time(const sub_signal &ss)
A helper function used to get the end of the range.
Definition: sub_signal.hpp:102
sub_signal & operator=(const sub_signal &ss)
The assignment operator.
Definition: sub_signal.hpp:67
friend std::function< CTTYPE(const sc_time &)> get_function(const sub_signal &ss)
A helper function used to get the functions in range.
Definition: sub_signal.hpp:110
friend void set_function(sub_signal &ss, const std::function< CTTYPE(const sc_time &)> &f)
A helper function used to set the function in the range.
Definition: sub_signal.hpp:127
sub_signal(const sub_signal &ss)
The copy constructor.
Definition: sub_signal.hpp:60
friend sc_time get_start_time(const sub_signal &ss)
A helper function used to get the beginning of the range.
Definition: sub_signal.hpp:94
sub_signal(const sc_time &st, const sc_time &et, const functype &f)
The constructor used for sub-signal definition.
Definition: sub_signal.hpp:47