1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #ifndef SPECTRUM_MODEL_H
22 #define SPECTRUM_MODEL_H
23 
24 #include <ns3/simple-ref-count.h>
25 #include <vector>
26 
27 namespace ns3 {
28 
29 /**
30  * \defgroup spectrum Spectrum Models
31  *
32  */
33 
34 /**
35  * \ingroup spectrum
36  *
37  * The building block of a SpectrumModel. This struct models
38  * a frequency band defined by the frequency interval [fl, fc] and
39  * with center frequency fc. Typically, the center frequency will be
40  * used for stuff such as propagation modeling, while the interval
41  * boundaries will be used for bandwidth calculation and for
42  * conversion between different SpectrumRepresentations.
43  *
44  */
45 struct BandInfo
46 {
47   double fl; //!< lower limit of subband
48   double fc; //!< center frequency
49   double fh; //!< upper limit of subband
50 };
51 
52 
53 /// Container of BandInfo
54 typedef std::vector<BandInfo> Bands;
55 
56 /// Uid for SpectrumModels
57 typedef uint32_t SpectrumModelUid_t;
58 
59 /**
60  * Set of frequency values implementing the domain of the functions in
61  * the Function Space defined by SpectrumValue. Frequency values are in
62  * Hz. It is intended that frequency values are non-negative, though
63  * this is not enforced.
64  *
65  */
66 class SpectrumModel : public SimpleRefCount<SpectrumModel>
67 {
68 public:
69   /**
70    * Comparison operator. Returns true if the two SpectumModels are identical
71    * \param lhs left operand
72    * \param rhs right operand
73    * \returns true if the two operands are identical
74    */
75   friend bool operator== (const SpectrumModel& lhs, const SpectrumModel& rhs);
76 
77   /**
78    * This constructs a SpectrumModel based on a given set of frequencies,
79    * which is assumed to be sorted by increasing frequency. The lower
80    * (resp. upper) frequency band limit is determined as the mean value
81    * between the center frequency of the considered band and the
82    * center frequency of the adjacent lower (resp. upper) band.
83    *
84    * @param centerFreqs the vector of center frequencies.
85    */
86   SpectrumModel (const std::vector<double>& centerFreqs);
87 
88 
89   /**
90    * This constructs a SpectrumModel based on the explicit values of
91    * center frequencies and boundaries of each subband.
92    *
93    * @param bands the vector of bands for this model
94    */
95   SpectrumModel (const Bands& bands);
96 
97   /**
98    * This constructs a SpectrumModel based on the explicit values of
99    * center frequencies and boundaries of each subband. This is used
100    * if <i>bands</i> is an rvalue.
101    *
102    * @param bands the vector of bands for this model
103    */
104   SpectrumModel (Bands&& bands);
105 
106   /**
107    *
108    * @return the number of frequencies in this SpectrumModel
109    */
110   size_t GetNumBands () const;
111 
112 
113   /**
114    *
115    * @return the unique id of this SpectrumModel
116    */
117   SpectrumModelUid_t GetUid () const;
118 
119   /**
120    * Const Iterator to the model Bands container start.
121    *
122    * @return a const iterator to the start of the vector of bands
123    */
124   Bands::const_iterator Begin () const;
125   /**
126    * Const Iterator to the model Bands container end.
127    *
128    * @return a const iterator to past-the-end of the vector of bands
129    */
130   Bands::const_iterator End () const;
131 
132   /**
133    * Check if another SpectrumModels has bands orthogonal to our bands.
134    *
135    * \param other another SpectrumModel
136    * \returns true if bands are orthogonal
137    */
138   bool IsOrthogonal (const SpectrumModel &other) const;
139 
140 private:
141   Bands m_bands;         //!< Actual definition of frequency bands within this SpectrumModel
142   SpectrumModelUid_t m_uid;        //!< unique id for a given set of frequencies
143   static SpectrumModelUid_t m_uidCount;    //!< counter to assign m_uids
144 };
145 
146 
147 } // namespace ns3
148 
149 #endif /* SPECTRUM_MODEL_H */
150