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-span.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2026 Universita' degli Studi di Napoli Federico II
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Stefano Avallone <stavallo@unina.it>
7
*/
8
9
#include "
time-span.h
"
10
11
#include "
assert.h
"
12
13
/**
14
* @file
15
* @ingroup time
16
* Declaration of class ns3::TimeSpan and definition of the TimeSpanValue attribute value.
17
*/
18
19
namespace
ns3
20
{
21
22
TimeSpan::TimeSpan
(
const
std::string& s)
23
{
24
std::istringstream iss{s};
25
iss >> *
this
;
26
}
27
28
TimeSpan::TimeSpan
(
const
Time
& begin,
const
Time
& end)
29
:
m_begin
(begin),
30
m_end
(end)
31
{
32
NS_ASSERT_MSG
(
m_begin
<=
m_end
,
33
"Begin time ("
<<
m_begin
<<
") must be less than or equal to end time ("
<<
m_end
34
<<
")"
);
35
}
36
37
TimeSpan
38
TimeSpan::Create
(
const
Time
& begin,
const
Time
& end)
39
{
40
return
TimeSpan
(begin, end);
41
}
42
43
Time
44
TimeSpan::Begin
()
const
45
{
46
return
m_begin
;
47
}
48
49
Time
50
TimeSpan::End
()
const
51
{
52
return
m_end
;
53
}
54
55
Time
56
TimeSpan::Duration
()
const
57
{
58
return
m_end
-
m_begin
;
59
}
60
61
std::ostream&
62
operator<<
(std::ostream& os,
const
TimeSpan
& timespan)
63
{
64
os <<
"{"
<< timespan.
Begin
() <<
", "
<< timespan.
End
() <<
"}"
;
65
return
os;
66
}
67
68
std::istream&
69
operator>>
(std::istream& is,
TimeSpan
& timespan)
70
{
71
char
openingBrace;
72
if
(!(is >> openingBrace) || openingBrace !=
'{'
)
73
{
74
NS_ABORT_MSG
(
"Can't parse TimeSpan: opening brace not found"
);
75
}
76
77
std::string beginStr;
78
if
(!std::getline(is, beginStr,
','
) || is.eof())
79
{
80
NS_ABORT_MSG
(
"Can't parse TimeSpan: ',' separator not found"
);
81
}
82
83
Time
begin;
84
std::istringstream beginStream{beginStr};
85
beginStream >> begin;
86
87
std::string endStr;
88
if
(!std::getline(is, endStr,
'}'
) || is.eof())
89
{
90
NS_ABORT_MSG
(
"Can't parse TimeSpan: closing brace not found"
);
91
}
92
93
Time
end;
94
std::istringstream endStream{endStr};
95
endStream >> end;
96
97
timespan =
TimeSpan
(begin, end);
98
return
is;
99
}
100
101
}
// namespace ns3
assert.h
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:95
ns3::TimeSpan
Class representing a period of time defined via a begin time and an end time.
Definition
time-span.h:30
ns3::TimeSpan::Duration
Time Duration() const
Definition
time-span.cc:56
ns3::TimeSpan::Create
static TimeSpan Create(const Time &begin, const Time &end)
TimeSpan factory (required by TimeSpanValue).
Definition
time-span.cc:38
ns3::TimeSpan::End
Time End() const
Definition
time-span.cc:50
ns3::TimeSpan::m_end
Time m_end
end time
Definition
time-span.h:85
ns3::TimeSpan::Begin
Time Begin() const
Definition
time-span.cc:44
ns3::TimeSpan::TimeSpan
TimeSpan()=default
ns3::TimeSpan::m_begin
Time m_begin
begin time
Definition
time-span.h:84
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition
assert.h:76
NS_ABORT_MSG
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition
abort.h:38
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition
angles.cc:148
ns3::operator>>
std::istream & operator>>(std::istream &is, Angles &a)
Definition
angles.cc:172
time-span.h
Declaration of class ns3::TimeSpan and definition of the TimeSpanValue attribute value.
src
core
model
time-span.cc
Generated on
for ns-3 by
1.16.1