gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sc_time.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * Authors: Gabe Black
28  */
29 
30 #ifndef __SYSTEMC_EXT_CORE_SC_TIME_HH__
31 #define __SYSTEMC_EXT_CORE_SC_TIME_HH__
32 
33 #include <stdint.h>
34 
35 #include <iostream>
36 
37 #include "../dt/int/sc_nbdefs.hh"
38 
39 namespace sc_core
40 {
41 
43  SC_FS = 0,
49 };
50 
51 class sc_time
52 {
53  public:
54  sc_time();
55  sc_time(double, sc_time_unit);
56  sc_time(const sc_time &);
57 
58  // Nonstandard
59  sc_time(double, const char *);
60 
61  // Deprecated
62  sc_time(double, bool);
63  sc_time(sc_dt::uint64, bool);
64 
65  sc_time &operator = (const sc_time &);
66 
67  sc_dt::uint64 value() const;
68  double to_double() const;
69  double to_seconds() const;
70  const std::string to_string() const;
71 
72  bool operator == (const sc_time &) const;
73  bool operator != (const sc_time &) const;
74  bool operator < (const sc_time &) const;
75  bool operator <= (const sc_time &) const;
76  bool operator > (const sc_time &) const;
77  bool operator >= (const sc_time &) const;
78 
79  sc_time &operator += (const sc_time &);
80  sc_time &operator -= (const sc_time &);
81  sc_time &operator *= (double);
82  sc_time &operator /= (double);
83 
84  void print(std::ostream & =std::cout) const;
85 
86  // Deprecated
88  static sc_time from_seconds(double);
89  static sc_time from_string(const char *str);
90 
91  private:
92  uint64_t val;
93 };
94 
95 const sc_time operator + (const sc_time &, const sc_time &);
96 const sc_time operator - (const sc_time &, const sc_time &);
97 
98 const sc_time operator * (const sc_time &, double);
99 const sc_time operator * (double, const sc_time &);
100 const sc_time operator / (const sc_time &, double);
101 double operator / (const sc_time &, const sc_time &);
102 
103 std::ostream &operator << (std::ostream &, const sc_time &);
104 
105 extern const sc_time SC_ZERO_TIME;
106 
109 const sc_time &sc_max_time();
110 
111 // Deprecated
114 
115 // Nonstandard
117 {
118  public:
119  sc_time_tuple() : _value(), _unit(SC_SEC), _set(false) {}
120  sc_time_tuple(const sc_time &);
121 
122  bool has_value() const;
123  sc_dt::uint64 value() const;
124  // Normalized unit.
125  sc_time_unit unit() const { return _unit; }
126  // Normalized unit symbol.
127  const char *unit_symbol() const;
128 
129  operator sc_time() const { return sc_time(to_double(), _unit); }
130 
131  double to_double() const; // Relative to the normalized unit.
132  std::string to_string() const;
133 
134  private:
137  bool _set;
138 };
139 
140 } // namespace sc_core
141 
142 #endif //__SYSTEMC_EXT_CORE_SC_TIME_HH__
bool operator<(const sc_time &) const
Definition: sc_time.cc:154
void print(std::ostream &=std::cout) const
Definition: sc_time.cc:206
sc_time_unit _unit
Definition: sc_time.hh:136
sc_time & operator+=(const sc_time &)
Definition: sc_time.cc:178
bool operator!=(const sc_time &) const
Definition: sc_time.cc:148
sc_time_unit unit() const
Definition: sc_time.hh:125
sc_time_unit
Definition: sc_time.hh:42
const sc_time operator/(const sc_time &t, double d)
Definition: sc_time.cc:273
bool operator==(const sc_time &) const
Definition: sc_time.cc:142
sc_time & operator*=(double)
Definition: sc_time.cc:192
sc_time & operator/=(double)
Definition: sc_time.cc:199
static sc_time from_string(const char *str)
Definition: sc_time.cc:230
std::ostream & operator<<(std::ostream &os, sc_status s)
Definition: sc_main.cc:181
static sc_time from_value(sc_dt::uint64)
Definition: sc_time.cc:212
sc_dt::uint64 _value
Definition: sc_time.hh:135
sc_dt::uint64 value() const
Definition: sc_time.cc:117
sc_time & operator=(const sc_time &)
Definition: sc_time.cc:110
sc_time & operator-=(const sc_time &)
Definition: sc_time.cc:185
double to_seconds() const
Definition: sc_time.cc:128
bool operator>(const sc_time &) const
Definition: sc_time.cc:166
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:292
const sc_time operator*(const sc_time &t, double d)
Definition: sc_time.cc:259
uint64_t uint64
Definition: sc_nbdefs.hh:172
static sc_time from_seconds(double)
Definition: sc_time.cc:222
const sc_time & sc_max_time()
Definition: sc_time.cc:347
sc_time sc_get_time_resolution()
Definition: sc_time.cc:341
const sc_time operator+(const sc_time &a, const sc_time &b)
Definition: sc_time.cc:247
const std::string to_string() const
Definition: sc_time.cc:134
double to_double() const
Definition: sc_time.cc:123
void sc_set_time_resolution(double d, sc_time_unit tu)
Definition: sc_time.cc:295
bool operator>=(const sc_time &) const
Definition: sc_time.cc:172
bool operator<=(const sc_time &) const
Definition: sc_time.cc:160
sc_time sc_get_default_time_unit()
Definition: sc_time.cc:392
uint64_t val
Definition: sc_time.hh:92
void sc_set_default_time_unit(double d, sc_time_unit tu)
Definition: sc_time.cc:354
const sc_time operator-(const sc_time &a, const sc_time &b)
Definition: sc_time.cc:253

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13