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 
28 /**
29  * \file
30  * \ingroup time
31  * ns3::DefaultTimePrinter implementation.
32  */
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("TimePrinter");
37 
38 void
DefaultTimePrinter(std::ostream & os)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 
66