A Discrete-Event Network Simulator
API
uan-tx-mode.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
19 */
20#include "uan-tx-mode.h"
21#include "ns3/log.h"
22#include <map>
23#include <utility>
24
25namespace ns3 {
26
27NS_LOG_COMPONENT_DEFINE ("UanTxMode");
28
30{
31}
32
34{
35}
36
37
40{
42}
43
46{
48}
49
52{
54}
55
58{
60}
61
64{
66}
67
70{
72}
73
74std::string
76{
78}
79
82{
83 return m_uid;
84}
85
86std::ostream &
87operator<< (std::ostream & os, const UanTxMode &mode)
88{
89 os << mode.m_uid;
90 return os;
91}
92
93std::istream &
94operator>> (std::istream & is, UanTxMode &mode)
95{
96 std::string name;
97 uint32_t duh;
98
99 is >> duh;
100
101 mode.m_uid = duh;
102 return is;
103}
104
105
106
108 : m_nextUid (0)
109{
110
111}
113{
114 m_modes.clear ();
115}
116bool
118{
119 std::map<uint32_t, UanTxModeItem>::iterator it = m_modes.begin ();
120
121 for (; it != m_modes.end (); it++)
122 {
123 if ((*it).second.m_name == name)
124 {
125 return true;
126 }
127 }
128 return false;
129}
130
133 uint32_t dataRateBps,
134 uint32_t phyRateSps,
135 uint32_t cfHz,
136 uint32_t bwHz,
137 uint32_t constSize,
138 std::string name)
139{
141
142
143 UanTxModeItem *item;
144
145 if (factory.NameUsed (name))
146 {
147 NS_LOG_WARN ("Redefining UanTxMode with name \"" << name << "\"");
148 item = &factory.GetModeItem (name);
149 }
150 else
151 {
152 item = &factory.m_modes[factory.m_nextUid];
153 item->m_uid = factory.m_nextUid++;
154 }
155
156 item->m_type = type;
157 item->m_dataRateBps = dataRateBps;
158 item->m_phyRateSps = phyRateSps;
159 item->m_cfHz = cfHz;
160 item->m_bwHz = bwHz;
161 item->m_constSize = constSize;
162 item->m_name = name;
163 return factory.MakeModeFromItem (*item);
164}
165
168{
169 if (uid >= m_nextUid)
170 {
171 NS_FATAL_ERROR ("Attempting to retrieve UanTxMode with uid, "
172 << uid << ", >= m_nextUid");
173 }
174
175 return m_modes[uid];
176}
177
180{
181 std::map<uint32_t, UanTxModeItem>::iterator it = m_modes.begin ();
182 for (; it != m_modes.end (); it++)
183 {
184 if ((*it).second.m_name == name)
185 {
186 return (*it).second;
187 }
188 }
189 NS_FATAL_ERROR ("Unknown mode, \"" << name << "\", requested from mode factory");
190 return (*it).second; // dummy to get rid of warning
191}
192
195{
197 return factory.MakeModeFromItem (factory.GetModeItem (name));
198}
199
202{
204 return factory.MakeModeFromItem (factory.GetModeItem (uid));
205}
206
209{
210 UanTxMode mode;
211 mode.m_uid = item.m_uid;
212 return mode;
213}
214
217{
218 static UanTxModeFactory factory;
219 return factory;
220}
221
223{
224}
225
227{
228 m_modes.clear ();
229}
230
231void
233{
234 m_modes.push_back (newMode);
235}
236
237void
239{
240 NS_ASSERT (modeNum < m_modes.size ());
241
242
243 std::vector<UanTxMode>::iterator it = m_modes.begin ();
244 for (uint32_t i = 0; i < modeNum; i++)
245 {
246 it++;
247 }
248 it = m_modes.erase (it);
249}
250
253{
254 NS_ASSERT (i < m_modes.size ());
255 return m_modes[i];
256}
257
260{
261 return static_cast<uint32_t> (m_modes.size ());
262}
263
264std::ostream &
265operator << (std::ostream &os, const UanModesList &ml)
266{
267
268 os << ml.GetNModes () << "|";
269
270 for (uint32_t i = 0; i < ml.m_modes.size (); i++)
271 {
272 os << ml[i] << "|";
273 }
274 return os;
275}
276std::istream &
277operator >> (std::istream &is, UanModesList &ml)
278{
279 char c;
280
281 int numModes;
282
283 is >> numModes >> c;
284 if (c != '|')
285 {
286 is.setstate (std::ios_base::failbit);
287 }
288 ml.m_modes.clear ();
289 ml.m_modes.resize (numModes);
290
291 for (int i = 0; i < numModes && !is.eof (); i++)
292 {
293 is >> ml.m_modes[i] >> c;
294 if (c != '|')
295 {
296 is.setstate (std::ios_base::failbit);
297 }
298 }
299
300 return is;
301}
302
304
305} // namespace ns3
Container for UanTxModes.
Definition: uan-tx-mode.h:258
void DeleteMode(uint32_t num)
Delete the mode at given index.
Definition: uan-tx-mode.cc:238
UanModesList()
Constructor.
Definition: uan-tx-mode.cc:222
uint32_t GetNModes(void) const
Get the number of modes in this list.
Definition: uan-tx-mode.cc:259
void AppendMode(UanTxMode mode)
Add mode to this list.
Definition: uan-tx-mode.cc:232
UanTxMode operator[](uint32_t index) const
Retrieve a mode by index.
Definition: uan-tx-mode.cc:252
virtual ~UanModesList()
Destructor.
Definition: uan-tx-mode.cc:226
std::vector< UanTxMode > m_modes
The vector of modes in this list.
Definition: uan-tx-mode.h:290
Global database of UanTxMode objects, retrievable by id or name.
Definition: uan-tx-mode.h:139
static UanTxMode CreateMode(UanTxMode::ModulationType type, uint32_t dataRateBps, uint32_t phyRateSps, uint32_t cfHz, uint32_t bwHz, uint32_t constSize, std::string name)
Definition: uan-tx-mode.cc:132
UanTxMode MakeModeFromItem(const UanTxModeItem &item)
Create a public UanTxMode from an internal UanTxModeItem.
Definition: uan-tx-mode.cc:208
UanTxModeFactory()
Constructor.
Definition: uan-tx-mode.cc:107
static UanTxMode GetMode(std::string name)
Get a mode by name.
Definition: uan-tx-mode.cc:194
std::map< uint32_t, UanTxModeItem > m_modes
Container for modes.
Definition: uan-tx-mode.h:208
static UanTxModeFactory & GetFactory(void)
Construct and get the static global factory instance.
Definition: uan-tx-mode.cc:216
~UanTxModeFactory()
Destructor.
Definition: uan-tx-mode.cc:112
bool NameUsed(std::string name)
Check if the mode name already exists.
Definition: uan-tx-mode.cc:117
uint32_t m_nextUid
next id number
Definition: uan-tx-mode.h:181
UanTxModeItem & GetModeItem(uint32_t uid)
Get a mode by id.
Definition: uan-tx-mode.cc:167
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:42
ModulationType
Modulation type.
Definition: uan-tx-mode.h:50
uint32_t GetDataRateBps(void) const
Get the data rate of the transmit mode.
Definition: uan-tx-mode.cc:45
std::string GetName(void) const
Get the mode name.
Definition: uan-tx-mode.cc:75
uint32_t GetCenterFreqHz(void) const
Get the transmission center frequency.
Definition: uan-tx-mode.cc:57
uint32_t GetBandwidthHz(void) const
Get the transmission signal bandwidth.
Definition: uan-tx-mode.cc:63
uint32_t GetConstellationSize(void) const
Get the number of constellation points in the modulation scheme.
Definition: uan-tx-mode.cc:69
uint32_t GetPhyRateSps(void) const
Get the physical signaling rate.
Definition: uan-tx-mode.cc:51
uint32_t GetUid(void) const
Get a unique id for the mode.
Definition: uan-tx-mode.cc:81
~UanTxMode()
Destructor.
Definition: uan-tx-mode.cc:33
ModulationType GetModType(void) const
Get the modulation type of the mode.
Definition: uan-tx-mode.cc:39
UanTxMode()
Constructor.
Definition: uan-tx-mode.cc:29
uint32_t m_uid
Mode id.
Definition: uan-tx-mode.h:111
#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_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
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:139
ATTRIBUTE_HELPER_CPP(Length)
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:162
Container for the UanTxMode properties.
Definition: uan-tx-mode.h:188
uint32_t m_constSize
Modulation constellation size (2 for BPSK, 4 for QPSK).
Definition: uan-tx-mode.h:194
uint32_t m_phyRateSps
Symbol rate in symbols per second.
Definition: uan-tx-mode.h:193
std::string m_name
Unique string name for this transmission mode.
Definition: uan-tx-mode.h:196
UanTxMode::ModulationType m_type
Modulation type.
Definition: uan-tx-mode.h:189
uint32_t m_bwHz
Bandwidth in Hz.
Definition: uan-tx-mode.h:191
uint32_t m_dataRateBps
Data rate in BPS.
Definition: uan-tx-mode.h:192
uint32_t m_cfHz
Center frequency in Hz.
Definition: uan-tx-mode.h:190