src/sysc/kernel/sc_time.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2005 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_time.h -- The time class.
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 #ifndef SC_TIME_H
00037 #define SC_TIME_H
00038 
00039 
00040 #include "sysc/datatypes/int/sc_nbdefs.h"
00041 #include "sysc/datatypes/fx/scfx_ieee.h"
00042 #include "sysc/utils/sc_iostream.h"
00043 #include "sysc/utils/sc_string.h"
00044 
00045 namespace sc_core {
00046 
00047 class sc_simcontext;
00048 
00049 
00050 // ----------------------------------------------------------------------------
00051 //  ENUM : sc_time_unit
00052 //
00053 //  Enumeration of time units.
00054 // ----------------------------------------------------------------------------
00055 
00056 enum sc_time_unit
00057 {
00058     SC_FS = 0,
00059     SC_PS,
00060     SC_NS,
00061     SC_US,
00062     SC_MS,
00063     SC_SEC
00064 };
00065 
00066 
00067 // ----------------------------------------------------------------------------
00068 //  CLASS : sc_time
00069 //
00070 //  The time class.
00071 // ----------------------------------------------------------------------------
00072 
00073 class sc_time
00074 {
00075 public:
00076 
00077     // constructors
00078 
00079     sc_time();
00080     sc_time( double, sc_time_unit );
00081     sc_time( double, sc_time_unit, sc_simcontext* );
00082     sc_time( double, bool scale );
00083     sc_time( sc_dt::uint64, bool scale );
00084     sc_time( const sc_time& );
00085 
00086 
00087     // assignment operator
00088 
00089     sc_time& operator = ( const sc_time& );
00090 
00091 
00092     // conversion functions
00093 
00094     sc_dt::uint64 value() const;      // relative to the time resolution
00095     double to_double() const;  // relative to the time resolution
00096     double to_default_time_units() const;
00097     double to_seconds() const;
00098     const std::string to_string() const;
00099 
00100 
00101     // relational operators
00102 
00103     bool operator == ( const sc_time& ) const;
00104     bool operator != ( const sc_time& ) const;
00105     bool operator <  ( const sc_time& ) const;
00106     bool operator <= ( const sc_time& ) const;
00107     bool operator >  ( const sc_time& ) const;
00108     bool operator >= ( const sc_time& ) const;
00109 
00110 
00111     // arithmetic operators
00112 
00113     sc_time& operator += ( const sc_time& );
00114     sc_time& operator -= ( const sc_time& );
00115 
00116     friend const sc_time operator + ( const sc_time&, const sc_time& );
00117     friend const sc_time operator - ( const sc_time&, const sc_time& );
00118 
00119     sc_time& operator *= ( double );
00120     sc_time& operator /= ( double );
00121 
00122     friend const sc_time operator * ( const sc_time&, double );
00123     friend const sc_time operator * ( double, const sc_time& );
00124     friend const sc_time operator / ( const sc_time&, double );
00125     friend double        operator / ( const sc_time&, const sc_time& );
00126 
00127 
00128     // print function
00129 
00130     void print( ::std::ostream& ) const;
00131 
00132 private:
00133 
00134     sc_dt::uint64 m_value;
00135 };
00136 
00137 
00138 // print operator
00139 
00140 inline ::std::ostream& operator << ( ::std::ostream&, const sc_time& );
00141 
00142 
00143 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00144 
00145 // constructors
00146 
00147 inline
00148 sc_time::sc_time()
00149 : m_value( 0 )
00150 {}
00151 
00152 inline
00153 sc_time::sc_time( const sc_time& t )
00154 : m_value( t.m_value )
00155 {}
00156 
00157 
00158 // assignment operator
00159 
00160 inline
00161 sc_time&
00162 sc_time::operator = ( const sc_time& t )
00163 {
00164     m_value = t.m_value;
00165     return *this;
00166 }
00167 
00168 
00169 // conversion functions
00170 
00171 inline
00172 sc_dt::uint64
00173 sc_time::value() const  // relative to the time resolution
00174 {
00175     return m_value;
00176 }
00177 
00178 
00179 inline
00180 double
00181 sc_time::to_double() const  // relative to the time resolution
00182 {
00183     return sc_dt::uint64_to_double( m_value );
00184 }
00185 
00186 
00187 // relational operators
00188 
00189 inline
00190 bool
00191 sc_time::operator == ( const sc_time& t ) const
00192 {
00193     return ( m_value == t.m_value );
00194 }
00195 
00196 inline
00197 bool
00198 sc_time::operator != ( const sc_time& t ) const
00199 {
00200     return ( m_value != t.m_value );
00201 }
00202 
00203 inline
00204 bool
00205 sc_time::operator < ( const sc_time& t ) const
00206 {
00207     return ( m_value < t.m_value );
00208 }
00209 
00210 inline
00211 bool
00212 sc_time::operator <= ( const sc_time& t ) const
00213 {
00214     return ( m_value <= t.m_value );
00215 }
00216 
00217 inline
00218 bool
00219 sc_time::operator > ( const sc_time& t ) const
00220 {
00221     return ( m_value > t.m_value );
00222 }
00223 
00224 inline
00225 bool
00226 sc_time::operator >= ( const sc_time& t ) const
00227 {
00228     return ( m_value >= t.m_value );
00229 }
00230 
00231 
00232 // arithmetic operators
00233 
00234 inline
00235 sc_time&
00236 sc_time::operator += ( const sc_time& t )
00237 {
00238     m_value += t.m_value;
00239     return *this;
00240 }
00241 
00242 inline
00243 sc_time&
00244 sc_time::operator -= ( const sc_time& t )
00245 {
00246     m_value -= t.m_value;
00247     return *this;
00248 }
00249 
00250 
00251 inline
00252 const sc_time
00253 operator + ( const sc_time& t1, const sc_time& t2 )
00254 {
00255     return sc_time( t1 ) += t2;
00256 }
00257 
00258 inline
00259 const sc_time
00260 operator - ( const sc_time& t1, const sc_time& t2 )
00261 {
00262     return sc_time( t1 ) -= t2;
00263 }
00264 
00265 
00266 inline
00267 sc_time&
00268 sc_time::operator *= ( double d )
00269 {
00270     // linux bug workaround; don't change next two lines
00271     volatile double tmp = sc_dt::uint64_to_double( m_value ) * d + 0.5;
00272     m_value = SCAST<sc_dt::int64>( tmp );
00273     return *this;
00274 }
00275 
00276 inline
00277 sc_time&
00278 sc_time::operator /= ( double d )
00279 {
00280     // linux bug workaround; don't change next two lines
00281     volatile double tmp = sc_dt::uint64_to_double( m_value ) / d + 0.5;
00282     m_value = SCAST<sc_dt::int64>( tmp );
00283     return *this;
00284 }
00285 
00286 
00287 inline
00288 const sc_time
00289 operator * ( const sc_time& t, double d )
00290 {
00291     sc_time tmp( t );
00292     return tmp *= d;
00293 }
00294 
00295 inline
00296 const sc_time
00297 operator * ( double d, const sc_time& t )
00298 {
00299     sc_time tmp( t );
00300     return tmp *= d;
00301 }
00302 
00303 inline
00304 const sc_time
00305 operator / ( const sc_time& t, double d )
00306 {
00307     sc_time tmp( t );
00308     return tmp /= d;
00309 }
00310 
00311 inline
00312 double
00313 operator / ( const sc_time& t1, const sc_time& t2 )
00314 {
00315     return ( t1.to_double() / t2.to_double() );
00316 }
00317 
00318 
00319 // print operator
00320 
00321 inline
00322 ::std::ostream&
00323 operator << ( ::std::ostream& os, const sc_time& t )
00324 {
00325     t.print( os );
00326     return os;
00327 }
00328 
00329 
00330 // ----------------------------------------------------------------------------
00331 //  STRUCT : sc_time_params
00332 //
00333 //  Struct that holds the time resolution and default time unit.
00334 // ----------------------------------------------------------------------------
00335 
00336 struct sc_time_params
00337 {
00338     double time_resolution;             // in femto seconds
00339     bool   time_resolution_specified;
00340     bool   time_resolution_fixed;
00341 
00342     sc_dt::uint64 default_time_unit;            // in time resolution
00343     bool   default_time_unit_specified;
00344 
00345     sc_time_params();
00346     ~sc_time_params();
00347 };
00348 
00349 
00350 // ----------------------------------------------------------------------------
00351 
00352 extern const sc_time SC_ZERO_TIME;
00353 
00354 
00355 // functions for accessing the time resolution and default time unit
00356 
00357 extern void    sc_set_time_resolution( double, sc_time_unit );
00358 extern sc_time sc_get_time_resolution();
00359 
00360 extern void    sc_set_default_time_unit( double, sc_time_unit );
00361 extern sc_time sc_get_default_time_unit();
00362 
00363 } // namespace sc_core
00364 
00365 #endif
00366 
00367 // Taf!

Generated on Wed Apr 25 13:53:27 2007 for SystemC by  doxygen 1.5.1