A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
25 NS_LOG_COMPONENT_DEFINE ("UanTxMode");
26 
27 namespace ns3 {
28 
30 {
31 }
32 
34 {
35 }
36 
37 
40 {
42 }
43 
44 uint32_t
46 {
48 }
49 
50 uint32_t
52 {
54 }
55 
56 uint32_t
58 {
60 }
61 
62 uint32_t
64 {
66 }
67 
68 uint32_t
70 {
72 }
73 
74 std::string
75 UanTxMode::GetName (void) const
76 {
78 }
79 
80 uint32_t
81 UanTxMode::GetUid (void) const
82 {
83  return m_uid;
84 }
85 
86 std::ostream &
87 operator<< (std::ostream & os, const UanTxMode &mode)
88 {
89  os << mode.m_uid;
90  return os;
91 }
92 
93 std::istream &
94 operator>> (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 }
116 bool
117 UanTxModeFactory::NameUsed (std::string name)
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 
131 UanTxMode
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 
193 UanTxMode
194 UanTxModeFactory::GetMode (std::string name)
195 {
197  return factory.MakeModeFromItem (factory.GetModeItem (name));
198 }
199 
200 UanTxMode
202 {
204  return factory.MakeModeFromItem (factory.GetModeItem (uid));
205 }
206 
207 UanTxMode
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 
231 void
233 {
234  m_modes.push_back (newMode);
235 }
236 
237 void
238 UanModesList::DeleteMode (uint32_t modeNum)
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 
251 UanTxMode
252 UanModesList::operator[] (uint32_t i) const
253 {
254  NS_ASSERT (i < m_modes.size ());
255  return m_modes[i];
256 }
257 
258 uint32_t
260 {
261  return m_modes.size ();
262 }
263 
264 std::ostream &
265 operator << (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 }
276 std::istream &
277 operator >> (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 
303 ATTRIBUTE_HELPER_CPP (UanModesList)
304  ;
305 
306 } // namespace ns3
Global database of UanTxMode objects, retrievable by id or name.
Definition: uan-tx-mode.h:138
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:49
uint32_t m_cfHz
Center frequency in Hz.
Definition: uan-tx-mode.h:190
uint32_t GetNModes(void) const
Get the number of modes in this list.
Definition: uan-tx-mode.cc:259
std::string GetName(void) const
Get the mode name.
Definition: uan-tx-mode.cc:75
~UanTxMode()
Destructor.
Definition: uan-tx-mode.cc:33
#define NS_ASSERT(condition)
Definition: assert.h:64
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
Container for UanTxModes.
Definition: uan-tx-mode.h:255
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
virtual ~UanModesList()
Destructor.
Definition: uan-tx-mode.cc:226
ModulationType GetModType(void) const
Get the modulation type of the mode.
Definition: uan-tx-mode.cc:39
uint32_t m_constSize
Modulation constellation size (2 for BPSK, 4 for QPSK).
Definition: uan-tx-mode.h:194
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
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
uint32_t m_dataRateBps
Data rate in BPS.
Definition: uan-tx-mode.h:192
uint32_t GetDataRateBps(void) const
Get the data rate of the transmit mode.
Definition: uan-tx-mode.cc:45
UanTxModeItem & GetModeItem(uint32_t uid)
Get a mode by id.
Definition: uan-tx-mode.cc:167
UanTxMode::ModulationType m_type
Modulation type.
Definition: uan-tx-mode.h:189
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
ModulationType
Modulation type.
Definition: uan-tx-mode.h:50
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
UanTxMode operator[](uint32_t index) const
Retrieve a mode by index.
Definition: uan-tx-mode.cc:252
uint32_t m_uid
Mode id.
Definition: uan-tx-mode.h:111
std::string m_name
Unique string name for this transmission mode.
Definition: uan-tx-mode.h:196
~UanTxModeFactory()
Destructor.
Definition: uan-tx-mode.cc:112
uint32_t m_phyRateSps
Symbol rate in symbols per second.
Definition: uan-tx-mode.h:193
uint32_t GetCenterFreqHz(void) const
Get the transmission center frequency.
Definition: uan-tx-mode.cc:57
UanTxMode()
Constructor.
Definition: uan-tx-mode.cc:29
UanModesList()
Constructor.
Definition: uan-tx-mode.cc:222
uint32_t m_nextUid
next id number
Definition: uan-tx-mode.h:181
uint32_t GetPhyRateSps(void) const
Get the physical signaling rate.
Definition: uan-tx-mode.cc:51
Container for the UanTxMode properties.
Definition: uan-tx-mode.h:187
#define NS_LOG_WARN(msg)
Definition: log.h:280
uint32_t m_bwHz
Bandwidth in Hz.
Definition: uan-tx-mode.h:191
void AppendMode(UanTxMode mode)
Add mode to this list.
Definition: uan-tx-mode.cc:232
NS_LOG_COMPONENT_DEFINE("UanTxMode")
UanTxMode MakeModeFromItem(const UanTxModeItem &item)
Create a public UanTxMode from an internal UanTxModeItem.
Definition: uan-tx-mode.cc:208
uint32_t GetConstellationSize(void) const
Get the number of constellation points in the modulation scheme.
Definition: uan-tx-mode.cc:69
ATTRIBUTE_HELPER_CPP(ObjectFactory)
uint32_t GetBandwidthHz(void) const
Get the transmission signal bandwidth.
Definition: uan-tx-mode.cc:63
bool NameUsed(std::string name)
Check if the mode name already exists.
Definition: uan-tx-mode.cc:117
uint32_t GetUid(void) const
Get a unique id for the mode.
Definition: uan-tx-mode.cc:81
std::vector< UanTxMode > m_modes
The vector of modes in this list.
Definition: uan-tx-mode.h:288
void DeleteMode(uint32_t num)
Delete the mode at given index.
Definition: uan-tx-mode.cc:238