A Discrete-Event Network Simulator
API
spectrum-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 
3 /*
4  * Copyright (c) 2009 CTTC
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Nicola Baldo <nbaldo@cttc.es>
20  */
21 
22 #include <cmath>
23 #include <cstddef>
24 #include <ns3/spectrum-model.h>
25 #include <ns3/log.h>
26 #include <ns3/assert.h>
27 
28 
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("SpectrumModel");
33 
34 bool operator== (const SpectrumModel& lhs, const SpectrumModel& rhs)
35 {
36  return (lhs.m_uid == rhs.m_uid);
37 }
38 
40 
41 SpectrumModel::SpectrumModel (std::vector<double> centerFreqs)
42 {
43  NS_ASSERT (centerFreqs.size () > 1);
44  m_uid = ++m_uidCount;
45 
46  for (std::vector<double>::const_iterator it = centerFreqs.begin ();
47  it != centerFreqs.end ();
48  ++it)
49  {
50  BandInfo e;
51  e.fc = *it;
52  if (it == centerFreqs.begin ())
53  {
54  double delta = ((*(it + 1)) - (*it)) / 2;
55  e.fl = *it - delta;
56  e.fh = *it + delta;
57  }
58  else if (it == centerFreqs.end () - 1 )
59  {
60  double delta = ((*it) - (*(it - 1))) / 2;
61  e.fl = *it - delta;
62  e.fh = *it + delta;
63  }
64  else
65  {
66  e.fl = ((*it) + (*(it - 1))) / 2;
67  e.fh = ((*(it + 1)) + (*it)) / 2;
68  }
69  m_bands.push_back (e);
70  }
71 }
72 
74 {
75  m_uid = ++m_uidCount;
76  NS_LOG_INFO ("creating new SpectrumModel, m_uid=" << m_uid);
77  m_bands = bands;
78 }
79 
80 Bands::const_iterator
82 {
83  return m_bands.begin ();
84 }
85 
86 Bands::const_iterator
88 {
89  return m_bands.end ();
90 }
91 
92 size_t
94 {
95  return m_bands.size ();
96 }
97 
100 {
101  return m_uid;
102 }
103 
104 bool
106 {
107  for (Bands::const_iterator myIt = Begin ();
108  myIt != End ();
109  ++myIt)
110  {
111  for (Bands::const_iterator otherIt = other.Begin ();
112  otherIt != other.End ();
113  ++otherIt)
114  {
115  if (std::max (myIt->fl, otherIt->fl) < std::min (myIt->fh, otherIt->fh))
116  {
117  return false;
118  }
119  }
120  }
121  return true;
122 }
123 
124 
125 } // namespace ns3
size_t GetNumBands() const
uint32_t SpectrumModelUid_t
Uid for SpectrumModels.
#define min(a, b)
Definition: 80211b.c:42
SpectrumModelUid_t m_uid
unique id for a given set of frequencies
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
bool IsOrthogonal(const SpectrumModel &other) const
Check if another SpectrumModels has bands orthogonal to our bands.
Set of frequency values implementing the domain of the functions in the Function Space defined by Spe...
std::vector< BandInfo > Bands
Container of BandInfo.
SpectrumModelUid_t GetUid() const
#define max(a, b)
Definition: 80211b.c:43
double fc
center frequency
static SpectrumModelUid_t m_uidCount
counter to assign m_uids
Bands::const_iterator Begin() const
Const Iterator to the model Bands container start.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double fl
lower limit of subband
Bands m_bands
Actual definition of frequency bands within this SpectrumModel.
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:137
double fh
upper limit of subband
SpectrumModel(std::vector< double > centerFreqs)
This constructs a SpectrumModel based on a given set of frequencies, which is assumed to be sorted by...
The building block of a SpectrumModel.
Bands::const_iterator End() const
Const Iterator to the model Bands container end.