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-2006 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 // $Log: sc_time.h,v $
00037 // Revision 1.1.1.1  2006/12/15 20:31:37  acg
00038 // SystemC 2.2
00039 //
00040 // Revision 1.3  2006/01/13 18:44:30  acg
00041 // Added $Log to record CVS changes into the source.
00042 //
00043 
00044 #ifndef SC_TIME_H
00045 #define SC_TIME_H
00046 
00047 
00048 #include "sysc/datatypes/int/sc_nbdefs.h"
00049 #include "sysc/datatypes/fx/scfx_ieee.h"
00050 #include "sysc/utils/sc_iostream.h"
00051 #include "sysc/utils/sc_string.h"
00052 
00053 namespace sc_core {
00054 
00055 class sc_simcontext;
00056 
00057 // friend operator declarations
00058 
00059     const sc_time operator + ( const sc_time&, const sc_time& );
00060     const sc_time operator - ( const sc_time&, const sc_time& );
00061     const sc_time operator * ( const sc_time&, double );
00062     const sc_time operator * ( double, const sc_time& );
00063     const sc_time operator / ( const sc_time&, double );
00064     double        operator / ( const sc_time&, const sc_time& );
00065 
00066 
00067 // ----------------------------------------------------------------------------
00068 //  ENUM : sc_time_unit
00069 //
00070 //  Enumeration of time units.
00071 // ----------------------------------------------------------------------------
00072 
00073 enum sc_time_unit
00074 {
00075     SC_FS = 0,
00076     SC_PS,
00077     SC_NS,
00078     SC_US,
00079     SC_MS,
00080     SC_SEC
00081 };
00082 
00083 
00084 // ----------------------------------------------------------------------------
00085 //  CLASS : sc_time
00086 //
00087 //  The time class.
00088 // ----------------------------------------------------------------------------
00089 
00090 class sc_time
00091 {
00092 public:
00093 
00094     // constructors
00095 
00096     sc_time();
00097     sc_time( double, sc_time_unit );
00098     sc_time( double, sc_time_unit, sc_simcontext* );
00099     sc_time( double, bool scale );
00100     sc_time( sc_dt::uint64, bool scale );
00101     sc_time( const sc_time& );
00102 
00103 
00104     // assignment operator
00105 
00106     sc_time& operator = ( const sc_time& );
00107 
00108 
00109     // conversion functions
00110 
00111     sc_dt::uint64 value() const;      // relative to the time resolution
00112     double to_double() const;  // relative to the time resolution
00113     double to_default_time_units() const;
00114     double to_seconds() const;
00115     const std::string to_string() const;
00116 
00117 
00118     // relational operators
00119 
00120     bool operator == ( const sc_time& ) const;
00121     bool operator != ( const sc_time& ) const;
00122     bool operator <  ( const sc_time& ) const;
00123     bool operator <= ( const sc_time& ) const;
00124     bool operator >  ( const sc_time& ) const;
00125     bool operator >= ( const sc_time& ) const;
00126 
00127 
00128     // arithmetic operators
00129 
00130     sc_time& operator += ( const sc_time& );
00131     sc_time& operator -= ( const sc_time& );
00132 
00133     friend const sc_time operator + ( const sc_time&, const sc_time& );
00134     friend const sc_time operator - ( const sc_time&, const sc_time& );
00135 
00136     sc_time& operator *= ( double );
00137     sc_time& operator /= ( double );
00138 
00139     friend const sc_time operator * ( const sc_time&, double );
00140     friend const sc_time operator * ( double, const sc_time& );
00141     friend const sc_time operator / ( const sc_time&, double );
00142     friend double        operator / ( const sc_time&, const sc_time& );
00143 
00144 
00145     // print function
00146 
00147     void print( ::std::ostream& os = std::cout ) const;
00148 
00149 private:
00150 
00151     sc_dt::uint64 m_value;
00152 };
00153 
00154 
00155 // print operator
00156 
00157 inline ::std::ostream& operator << ( ::std::ostream&, const sc_time& );
00158 
00159 
00160 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00161 
00162 // constructors
00163 
00164 inline
00165 sc_time::sc_time()
00166 : m_value( 0 )
00167 {}
00168 
00169 inline
00170 sc_time::sc_time( const sc_time& t )
00171 : m_value( t.m_value )
00172 {}
00173 
00174 
00175 // assignment operator
00176 
00177 inline
00178 sc_time&
00179 sc_time::operator = ( const sc_time& t )
00180 {
00181     m_value = t.m_value;
00182     return *this;
00183 }
00184 
00185 
00186 // conversion functions
00187 
00188 inline
00189 sc_dt::uint64
00190 sc_time::value() const  // relative to the time resolution
00191 {
00192     return m_value;
00193 }
00194 
00195 
00196 inline
00197 double
00198 sc_time::to_double() const  // relative to the time resolution
00199 {
00200     return sc_dt::uint64_to_double( m_value );
00201 }
00202 
00203 
00204 // relational operators
00205 
00206 inline
00207 bool
00208 sc_time::operator == ( const sc_time& t ) const
00209 {
00210     return ( m_value == t.m_value );
00211 }
00212 
00213 inline
00214 bool
00215 sc_time::operator != ( const sc_time& t ) const
00216 {
00217     return ( m_value != t.m_value );
00218 }
00219 
00220 inline
00221 bool
00222 sc_time::operator < ( const sc_time& t ) const
00223 {
00224     return ( m_value < t.m_value );
00225 }
00226 
00227 inline
00228 bool
00229 sc_time::operator <= ( const sc_time& t ) const
00230 {
00231     return ( m_value <= t.m_value );
00232 }
00233 
00234 inline
00235 bool
00236 sc_time::operator > ( const sc_time& t ) const
00237 {
00238     return ( m_value > t.m_value );
00239 }
00240 
00241 inline
00242 bool
00243 sc_time::operator >= ( const sc_time& t ) const
00244 {
00245     return ( m_value >= t.m_value );
00246 }
00247 
00248 
00249 // arithmetic operators
00250 
00251 inline
00252 sc_time&
00253 sc_time::operator += ( const sc_time& t )
00254 {
00255     m_value += t.m_value;
00256     return *this;
00257 }
00258 
00259 inline
00260 sc_time&
00261 sc_time::operator -= ( const sc_time& t )
00262 {
00263     m_value -= t.m_value;
00264     return *this;
00265 }
00266 
00267 
00268 inline
00269 const sc_time
00270 operator + ( const sc_time& t1, const sc_time& t2 )
00271 {
00272     return sc_time( t1 ) += t2;
00273 }
00274 
00275 inline
00276 const sc_time
00277 operator - ( const sc_time& t1, const sc_time& t2 )
00278 {
00279     return sc_time( t1 ) -= t2;
00280 }
00281 
00282 
00283 inline
00284 sc_time&
00285 sc_time::operator *= ( double d )
00286 {
00287     // linux bug workaround; don't change next two lines
00288     volatile double tmp = sc_dt::uint64_to_double( m_value ) * d + 0.5;
00289     m_value = SCAST<sc_dt::int64>( tmp );
00290     return *this;
00291 }
00292 
00293 inline
00294 sc_time&
00295 sc_time::operator /= ( double d )
00296 {
00297     // linux bug workaround; don't change next two lines
00298     volatile double tmp = sc_dt::uint64_to_double( m_value ) / d + 0.5;
00299     m_value = SCAST<sc_dt::int64>( tmp );
00300     return *this;
00301 }
00302 
00303 
00304 inline
00305 const sc_time
00306 operator * ( const sc_time& t, double d )
00307 {
00308     sc_time tmp( t );
00309     return tmp *= d;
00310 }
00311 
00312 inline
00313 const sc_time
00314 operator * ( double d, const sc_time& t )
00315 {
00316     sc_time tmp( t );
00317     return tmp *= d;
00318 }
00319 
00320 inline
00321 const sc_time
00322 operator / ( const sc_time& t, double d )
00323 {
00324     sc_time tmp( t );
00325     return tmp /= d;
00326 }
00327 
00328 inline
00329 double
00330 operator / ( const sc_time& t1, const sc_time& t2 )
00331 {
00332     return ( t1.to_double() / t2.to_double() );
00333 }
00334 
00335 
00336 // print operator
00337 
00338 inline
00339 ::std::ostream&
00340 operator << ( ::std::ostream& os, const sc_time& t )
00341 {
00342     t.print( os );
00343     return os;
00344 }
00345 
00346 
00347 // ----------------------------------------------------------------------------
00348 //  STRUCT : sc_time_params
00349 //
00350 //  Struct that holds the time resolution and default time unit.
00351 // ----------------------------------------------------------------------------
00352 
00353 struct sc_time_params
00354 {
00355     double time_resolution;     // in femto seconds
00356     bool   time_resolution_specified;
00357     bool   time_resolution_fixed;
00358 
00359     sc_dt::uint64 default_time_unit;        // in time resolution
00360     bool   default_time_unit_specified;
00361 
00362     sc_time_params();
00363     ~sc_time_params();
00364 };
00365 
00366 
00367 // ----------------------------------------------------------------------------
00368 
00369 extern const sc_time SC_ZERO_TIME;
00370 
00371 
00372 // functions for accessing the time resolution and default time unit
00373 
00374 extern void    sc_set_time_resolution( double, sc_time_unit );
00375 extern sc_time sc_get_time_resolution();
00376 
00377 extern void    sc_set_default_time_unit( double, sc_time_unit );
00378 extern sc_time sc_get_default_time_unit();
00379 
00380 } // namespace sc_core
00381 
00382 #endif
00383 
00384 // Taf!

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5