A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
time-span.h
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#ifndef TIME_SPAN_H
10#define TIME_SPAN_H
11
12#include "nstime.h"
13#include "struct.h"
14
15/**
16 * @file
17 * @ingroup time
18 * Declaration of class ns3::TimeSpan and definition of the TimeSpanValue attribute value.
19 */
20
21namespace ns3
22{
23
24/**
25 * Class representing a period of time defined via a begin time and an end time. An object of this
26 * class can also be set/get via the attribute system by using the @ref TimeSpanValue attribute
27 * value.
28 */
30{
31 public:
32 TimeSpan() = default;
33
34 /**
35 * Construct a TimeSpan from a string.
36 *
37 * The string representation is "{begin, end}". Whitespace around the begin and end times
38 * is allowed.
39 *
40 * @param s The string to parse into a TimeSpan
41 */
42 explicit TimeSpan(const std::string& s);
43
44 /**
45 * Construct a TimeSpan from a begin time and an end time.
46 *
47 * @param begin the begin time
48 * @param end the end time
49 */
50 TimeSpan(const Time& begin, const Time& end);
51
52 /**
53 * @brief TimeSpan factory (required by @ref TimeSpanValue)
54 * @param begin the begin time
55 * @param end the end time
56 * @return a TimeSpan object
57 */
58 static TimeSpan Create(const Time& begin, const Time& end);
59
60 /**
61 * @return the begin time
62 */
63 Time Begin() const;
64
65 /**
66 * @return the end time
67 */
68 Time End() const;
69
70 /**
71 * @return the duration of the timespan
72 */
73 Time Duration() const;
74
75 /**
76 * Compare two TimeSpan objects for equality.
77 *
78 * @param other The TimeSpan to compare with
79 * @return true if both TimeSpan objects have the same begin and end times
80 */
81 bool operator==(const TimeSpan& other) const = default;
82
83 private:
84 Time m_begin; //!< begin time
85 Time m_end; //!< end time
86};
87
88/**
89 * TimeSpan output streamer.
90 *
91 * Generates output such as "{10ms, 50ms}".
92 *
93 * @param [in,out] os The output stream.
94 * @param [in] timespan The timespan to put on the stream.
95 * @return The stream.
96 */
97std::ostream& operator<<(std::ostream& os, const TimeSpan& timespan);
98
99/**
100 * TimeSpan input streamer.
101 *
102 * The string representation is "{begin, end}". Whitespace around the begin and end times is
103 * allowed.
104 *
105 * @param [in,out] is The input stream.
106 * @param [out] timespan The TimeSpan variable to set from the stream data.
107 * @return The stream.
108 */
109std::istream& operator>>(std::istream& is, TimeSpan& timespan);
110
111/// @brief Definition of the TimeSpanValue attribute value
116
117} // namespace ns3
118
119#endif /* TIME_SPAN_H */
AttributeValue implementation for structures.
Definition struct.h:144
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Class representing a period of time defined via a begin time and an end time.
Definition time-span.h:30
Time Duration() const
Definition time-span.cc:56
static TimeSpan Create(const Time &begin, const Time &end)
TimeSpan factory (required by TimeSpanValue).
Definition time-span.cc:38
Time End() const
Definition time-span.cc:50
Time m_end
end time
Definition time-span.h:85
bool operator==(const TimeSpan &other) const =default
Compare two TimeSpan objects for equality.
Time Begin() const
Definition time-span.cc:44
TimeSpan()=default
Time m_begin
begin time
Definition time-span.h:84
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
StructValue< TimeSpan, StructConstructor<&TimeSpan::Create >, StructField< TimeValue, &TimeSpan::Begin >, StructField< TimeValue, &TimeSpan::End > > TimeSpanValue
Definition of the TimeSpanValue attribute value.
Definition time-span.h:112
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
Guidelines for defining attributes represented by structures.
Describe a function that constructs a structure from its field values.
Definition struct.h:262
Describe a structure field and the AttributeValue used to represent it.
Definition struct.h:227