A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
uan-tx-mode.cc
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 
29 UanTxMode::UanTxMode ()
30 {
31 }
32 
33 UanTxMode::~UanTxMode ()
34 {
35 }
36 
37 
40 {
41  return UanTxModeFactory::GetFactory ().GetModeItem (m_uid).m_type;
42 }
43 
44 uint32_t
46 {
47  return UanTxModeFactory::GetFactory ().GetModeItem (m_uid).m_dataRateBps;
48 }
49 
50 uint32_t
52 {
53  return UanTxModeFactory::GetFactory ().GetModeItem (m_uid).m_phyRateSps;
54 }
55 
56 uint32_t
58 {
59  return UanTxModeFactory::GetFactory ().GetModeItem (m_uid).m_cfHz;
60 }
61 
62 uint32_t
64 {
65  return UanTxModeFactory::GetFactory ().GetModeItem (m_uid).m_bwHz;
66 }
67 
68 uint32_t
70 {
71  return UanTxModeFactory::GetFactory ().GetModeItem (m_uid).m_constSize;
72 }
73 
74 std::string
75 UanTxMode::GetName (void) const
76 {
77  return UanTxModeFactory::GetFactory ().GetModeItem (m_uid).m_name;
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 
107 UanTxModeFactory::UanTxModeFactory ()
108  : m_nextUid (0)
109 {
110 
111 }
112 UanTxModeFactory::~UanTxModeFactory ()
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
132 UanTxModeFactory::CreateMode (UanTxMode::ModulationType type,
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 {
140  UanTxModeFactory &factory = UanTxModeFactory::GetFactory ();
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 
167 UanTxModeFactory::GetModeItem (uint32_t uid)
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 
178 UanTxModeFactory::UanTxModeItem &
179 UanTxModeFactory::GetModeItem (std::string name)
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 {
196  UanTxModeFactory &factory = UanTxModeFactory::GetFactory ();
197  return factory.MakeModeFromItem (factory.GetModeItem (name));
198 }
199 
200 UanTxMode
201 UanTxModeFactory::GetMode (uint32_t uid)
202 {
203  UanTxModeFactory &factory = UanTxModeFactory::GetFactory ();
204  return factory.MakeModeFromItem (factory.GetModeItem (uid));
205 }
206 
207 UanTxMode
208 UanTxModeFactory::MakeModeFromItem (const UanTxModeItem &item)
209 {
210  UanTxMode mode;
211  mode.m_uid = item.m_uid;
212  return mode;
213 }
214 
215 UanTxModeFactory &
216 UanTxModeFactory::GetFactory (void)
217 {
218  static UanTxModeFactory factory;
219  return factory;
220 }
221 
222 UanModesList::UanModesList (void)
223 {
224 }
225 
226 UanModesList::~UanModesList (void)
227 {
228  m_modes.clear ();
229 }
230 
231 void
232 UanModesList::AppendMode (UanTxMode newMode)
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
259 UanModesList::GetNModes (void) const
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; 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 } // namespace ns3
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:49
uint32_t GetNModes(void) const
Definition: uan-tx-mode.cc:259
std::string GetName(void) const
Definition: uan-tx-mode.cc:75
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
Container for UanTxModes.
Definition: uan-tx-mode.h:162
ModulationType GetModType(void) const
Definition: uan-tx-mode.cc:39
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
uint32_t GetDataRateBps(void) const
Definition: uan-tx-mode.cc:45
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:36
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
uint32_t GetCenterFreqHz(void) const
Definition: uan-tx-mode.cc:57
#define ATTRIBUTE_HELPER_CPP(type)
uint32_t GetPhyRateSps(void) const
Definition: uan-tx-mode.cc:51
#define NS_LOG_WARN(msg)
Definition: log.h:246
uint32_t GetConstellationSize(void) const
Definition: uan-tx-mode.cc:69
uint32_t GetBandwidthHz(void) const
Definition: uan-tx-mode.cc:63
uint32_t GetUid(void) const
Definition: uan-tx-mode.cc:81