A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
time-printer.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2018 Lawrence Livermore National Laboratory
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
19
*/
20
21
#include "
log.h
"
22
#include "
time-printer.h
"
23
#include "
simulator.h
"
// Now()
24
#include "
nstime.h
"
25
26
#include <iomanip>
27
34
namespace
ns3
{
35
36
NS_LOG_COMPONENT_DEFINE
(
"TimePrinter"
);
37
38
void
39
DefaultTimePrinter
(std::ostream &os)
40
{
41
std::ios_base::fmtflags ff = os.flags ();
// Save stream flags
42
std::streamsize oldPrecision = os.precision ();
43
os << std::fixed;
44
switch
(
Time::GetResolution
())
45
{
46
// *NS_CHECK_STYLE_OFF*
47
case
Time::US
: os << std::setprecision (6);
break
;
48
case
Time::NS
: os << std::setprecision (9);
break
;
49
case
Time::PS
: os << std::setprecision (12);
break
;
50
case
Time::FS
: os << std::setprecision (15);
break
;
51
// *NS_CHECK_STYLE_ON*
52
53
default
:
54
// default C++ precision of 5
55
os << std::setprecision (5);
56
}
57
os <<
Simulator::Now
().
As
(
Time::S
);
58
59
os << std::setprecision (oldPrecision);
60
os.flags (ff);
// Restore stream flags
61
}
62
63
64
}
// namespace ns3
65
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition:
simulator.cc:195
ns3::Time::GetResolution
static enum Unit GetResolution(void)
Definition:
time.cc:410
ns3::Time::US
@ US
microsecond
Definition:
nstime.h:116
ns3::Time::PS
@ PS
picosecond
Definition:
nstime.h:118
ns3::Time::FS
@ FS
femtosecond
Definition:
nstime.h:119
ns3::Time::S
@ S
second
Definition:
nstime.h:114
ns3::Time::NS
@ NS
nanosecond
Definition:
nstime.h:117
ns3::Time::As
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition:
time.cc:418
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
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:39
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 Tue Feb 6 2024 19:21:17 for ns-3 by
1.9.1