A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-interference-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Fraunhofer FKIE
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author:
7 * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
8 */
10
11#include <ns3/log.h>
12#include <ns3/spectrum-model.h>
13#include <ns3/spectrum-value.h>
14
15namespace ns3
16{
17namespace lrwpan
18{
19
20NS_LOG_COMPONENT_DEFINE("LrWpanInterferenceHelper");
21
23 : m_spectrumModel(spectrumModel),
24 m_dirty(false)
25{
27}
28
35
36bool
38{
39 NS_LOG_FUNCTION(this << signal);
40
41 bool result = false;
42
43 if (signal->GetSpectrumModel() == m_spectrumModel)
44 {
45 result = m_signals.insert(signal).second;
46 if (result && !m_dirty)
47 {
48 *m_signal += *signal;
49 }
50 }
51 return result;
52}
53
54bool
56{
57 NS_LOG_FUNCTION(this << signal);
58
59 bool result = false;
60
61 if (signal->GetSpectrumModel() == m_spectrumModel)
62 {
63 result = (m_signals.erase(signal) == 1);
64 if (result)
65 {
66 m_dirty = true;
67 }
68 }
69 return result;
70}
71
72void
74{
75 NS_LOG_FUNCTION(this);
76
77 m_signals.clear();
78 m_dirty = true;
79}
80
83{
84 NS_LOG_FUNCTION(this);
85
86 if (m_dirty)
87 {
88 // Sum up the current interference PSD.
90 for (auto it = m_signals.begin(); it != m_signals.end(); ++it)
91 {
92 *m_signal += *(*it);
93 }
94 m_dirty = false;
95 }
96
97 return m_signal->Copy();
98}
99
100} // namespace lrwpan
101} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Ptr< SpectrumValue > GetSignalPsd() const
Get the sum of all accumulated signals.
bool AddSignal(Ptr< const SpectrumValue > signal)
Add the given signal to the set of accumulated signals.
void ClearSignals()
Remove all currently accumulated signals.
std::set< Ptr< const SpectrumValue > > m_signals
The set of accumulated signals.
Ptr< SpectrumValue > m_signal
The precomputed sum of all accumulated signals.
bool m_dirty
Mark m_signal as dirty, whenever a signal is added or removed.
LrWpanInterferenceHelper(Ptr< const SpectrumModel > spectrumModel)
Create a new interference helper for the given SpectrumModel.
Ptr< const SpectrumModel > m_spectrumModel
The helpers SpectrumModel.
bool RemoveSignal(Ptr< const SpectrumValue > signal)
Remove the given signal to the set of accumulated signals.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.