A Discrete-Event Network Simulator
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
34namespace ns3 {
35
36NS_LOG_COMPONENT_DEFINE ("TimePrinter");
37
38void
39DefaultTimePrinter (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
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
static enum Unit GetResolution(void)
Definition: time.cc:424
@ US
microsecond
Definition: nstime.h:116
@ PS
picosecond
Definition: nstime.h:118
@ FS
femtosecond
Definition: nstime.h:119
@ S
second
Definition: nstime.h:114
@ NS
nanosecond
Definition: nstime.h:117
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:432
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void DefaultTimePrinter(std::ostream &os)
Default Time printer.
Definition: time-printer.cc:39
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
ns3::Simulator declaration.
Declaration of ns3::TimePrinter function pointer type and ns3::DefaultTimePrinter function.