Changeset 4 for sources/src/sc_time.cc


Ignore:
Timestamp:
Mar 10, 2008, 12:37:25 PM (16 years ago)
Author:
nipo
Message:

Towards SystemC-2.2 LRM:

  • Implement sc_time with units
  • Have a systemc header with no namespace pollution
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/src/sc_time.cc

    r1 r4  
    3939#include <sys/time.h>
    4040#include <string>
    41 
    42 using namespace std;
     41#include <sstream>
    4342
    4443namespace sc_core {
    4544
    46 uint64 nb_cycles = 0;
     45static const char *const unit_repr_string[6] =
     46{
     47        "FS", "PS", "NS", "US", "MS", "SEC"
     48};
     49
     50uint64_t nb_cycles = 0;
    4751
    4852const sc_time SC_ZERO_TIME(0,SC_NS);
     
    5155sc_time::sc_time (const sc_time &t)
    5256{
    53   time = t.time;
     57        *this = t;
    5458}
    5559
    5660sc_time::sc_time (double val, sc_time_unit tu)
    5761{
    58   time = (long long int) val;
     62  time = (uint64_t) val;
     63  unit = tu;
    5964}
    6065
     
    6469{
    6570  time = t.time;
     71  unit = t.unit;
     72  return *this;
    6673}
    6774
    6875
    69 const string
     76const std::string
    7077sc_time::to_string () const
    7178{
    72         char  res[32];
    73   const char* unit;
    74         if (time == 0)
    75   {
    76     unit = "s";
    77   } else
    78     unit = "ns";
    79   sprintf (res, "%lld %s", time, unit);
    80   return (string)res;
     79        std::ostringstream o;
     80        o << time << ' ' << unit_repr_string[unit];
     81        return o.str();
    8182}
    8283
Note: See TracChangeset for help on using the changeset viewer.