A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
time-printer.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018 Lawrence Livermore National Laboratory
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7
*/
8
9
#include "
time-printer.h
"
10
11
#include "
log.h
"
12
#include "
nstime.h
"
13
#include "
simulator.h
"
// Now()
14
15
#include <iomanip>
16
17
/**
18
* \file
19
* \ingroup time
20
* ns3::DefaultTimePrinter implementation.
21
*/
22
23
namespace
ns3
24
{
25
26
NS_LOG_COMPONENT_DEFINE
(
"TimePrinter"
);
27
28
void
29
DefaultTimePrinter
(std::ostream& os)
30
{
31
std::ios_base::fmtflags ff = os.flags();
// Save stream flags
32
std::streamsize oldPrecision = os.precision();
33
os << std::fixed;
34
switch
(
Time::GetResolution
())
35
{
36
case
Time::US
:
37
os << std::setprecision(6);
38
break
;
39
case
Time::NS
:
40
os << std::setprecision(9);
41
break
;
42
case
Time::PS
:
43
os << std::setprecision(12);
44
break
;
45
case
Time::FS
:
46
os << std::setprecision(15);
47
break
;
48
49
default
:
50
// default C++ precision of 5
51
os << std::setprecision(5);
52
}
53
os <<
Simulator::Now
().
As
(
Time::S
);
54
55
os << std::setprecision(oldPrecision);
56
os.flags(ff);
// Restore stream flags
57
}
58
59
}
// namespace ns3
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::Time::As
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition
time.cc:404
ns3::Time::GetResolution
static Unit GetResolution()
Definition
time.cc:397
ns3::Time::US
@ US
microsecond
Definition
nstime.h:107
ns3::Time::PS
@ PS
picosecond
Definition
nstime.h:109
ns3::Time::FS
@ FS
femtosecond
Definition
nstime.h:110
ns3::Time::S
@ S
second
Definition
nstime.h:105
ns3::Time::NS
@ NS
nanosecond
Definition
nstime.h:108
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
log.h
Debug message logging.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DefaultTimePrinter
void DefaultTimePrinter(std::ostream &os)
Default Time printer.
Definition
time-printer.cc:29
nstime.h
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
simulator.h
ns3::Simulator declaration.
time-printer.h
Declaration of ns3::TimePrinter function pointer type and ns3::DefaultTimePrinter function.
src
core
model
time-printer.cc
Generated on Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0