A Discrete-Event Network Simulator
API
spectrum-value.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 CTTC
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Nicola Baldo <nbaldo@cttc.es>
18  */
19 
20 #ifndef SPECTRUM_VALUE_H
21 #define SPECTRUM_VALUE_H
22 
23 #include "spectrum-model.h"
24 
25 #include <ns3/ptr.h>
26 #include <ns3/simple-ref-count.h>
27 
28 #include <ostream>
29 #include <vector>
30 
31 namespace ns3
32 {
33 
35 typedef std::vector<double> Values;
36 
60 class SpectrumValue : public SimpleRefCount<SpectrumValue>
61 {
62  public:
81 
82  SpectrumValue();
83 
91  double& operator[](size_t index);
92 
100  const double& operator[](size_t index) const;
101 
107 
113 
119  Bands::const_iterator ConstBandsBegin() const;
120 
126  Bands::const_iterator ConstBandsEnd() const;
127 
133  Values::const_iterator ConstValuesBegin() const;
134 
140  Values::const_iterator ConstValuesEnd() const;
141 
147  Values::iterator ValuesBegin();
148 
154  Values::iterator ValuesEnd();
155 
160  uint32_t GetValuesN() const;
161 
166  inline void SetValues(Values& values)
167  {
169  values.size() == m_spectrumModel->GetNumBands(),
170  "Values size does not correspond to the SpectrumModel in use by this SpectrumValue.");
171  m_values = values;
172  }
173 
178  inline void SetValues(Values&& values)
179  {
181  values.size() == m_spectrumModel->GetNumBands(),
182  "Values size does not correspond to the SpectrumModel in use by this SpectrumValue.");
183  m_values = std::move(values);
184  }
185 
191  inline Values& GetValues()
192  {
193  return m_values;
194  }
195 
201  inline const Values& GetValues() const
202  {
203  return m_values;
204  }
205 
211  const double& ValuesAt(uint32_t pos) const;
212 
221  friend SpectrumValue operator+(const SpectrumValue& lhs, const SpectrumValue& rhs);
222 
231  friend SpectrumValue operator+(const SpectrumValue& lhs, double rhs);
232 
241  friend SpectrumValue operator+(double lhs, const SpectrumValue& rhs);
242 
251  friend SpectrumValue operator-(const SpectrumValue& lhs, const SpectrumValue& rhs);
252 
261  friend SpectrumValue operator-(const SpectrumValue& lhs, double rhs);
262 
271  friend SpectrumValue operator-(double lhs, const SpectrumValue& rhs);
272 
281  friend SpectrumValue operator*(const SpectrumValue& lhs, const SpectrumValue& rhs);
282 
291  friend SpectrumValue operator*(const SpectrumValue& lhs, double rhs);
292 
301  friend SpectrumValue operator*(double lhs, const SpectrumValue& rhs);
302 
311  friend SpectrumValue operator/(const SpectrumValue& lhs, const SpectrumValue& rhs);
312 
321  friend SpectrumValue operator/(const SpectrumValue& lhs, double rhs);
322 
331  friend SpectrumValue operator/(double lhs, const SpectrumValue& rhs);
332 
341  friend bool operator==(const SpectrumValue& lhs, const SpectrumValue& rhs);
342 
351  friend bool operator!=(const SpectrumValue& lhs, const SpectrumValue& rhs);
352 
359  friend SpectrumValue operator+(const SpectrumValue& rhs);
360 
367  friend SpectrumValue operator-(const SpectrumValue& rhs);
368 
378  SpectrumValue operator<<(int n) const;
379 
389  SpectrumValue operator>>(int n) const;
390 
399 
408 
417 
426 
435  SpectrumValue& operator+=(double rhs);
436 
445  SpectrumValue& operator-=(double rhs);
446 
455  SpectrumValue& operator*=(double rhs);
456 
465  SpectrumValue& operator/=(double rhs);
466 
475  SpectrumValue& operator=(double rhs);
476 
484  friend double Norm(const SpectrumValue& x);
485 
493  friend double Sum(const SpectrumValue& x);
494 
501  friend double Prod(const SpectrumValue& x);
502 
511  friend SpectrumValue Pow(const SpectrumValue& lhs, double rhs);
512 
520  friend SpectrumValue Pow(double lhs, const SpectrumValue& rhs);
521 
529  friend SpectrumValue Log10(const SpectrumValue& arg);
530 
538  friend SpectrumValue Log2(const SpectrumValue& arg);
539 
547  friend SpectrumValue Log(const SpectrumValue& arg);
548 
556  friend double Integral(const SpectrumValue& arg);
557 
562  Ptr<SpectrumValue> Copy() const;
563 
572  typedef void (*TracedCallback)(Ptr<SpectrumValue> value);
573 
574  private:
579  void Add(const SpectrumValue& x);
584  void Add(double s);
589  void Subtract(const SpectrumValue& x);
594  void Subtract(double s);
599  void Multiply(const SpectrumValue& x);
604  void Multiply(double s);
609  void Divide(const SpectrumValue& x);
614  void Divide(double s);
618  void ChangeSign();
623  void ShiftLeft(int n);
628  void ShiftRight(int n);
634  void Pow(double exp);
641  void Exp(double base);
645  void Log10();
649  void Log2();
653  void Log();
654 
656 
665 };
666 
667 std::ostream& operator<<(std::ostream& os, const SpectrumValue& pvf);
668 
669 double Norm(const SpectrumValue& x);
670 double Sum(const SpectrumValue& x);
671 double Prod(const SpectrumValue& x);
672 SpectrumValue Pow(const SpectrumValue& lhs, double rhs);
673 SpectrumValue Pow(double lhs, const SpectrumValue& rhs);
674 SpectrumValue Log10(const SpectrumValue& arg);
675 SpectrumValue Log2(const SpectrumValue& arg);
676 SpectrumValue Log(const SpectrumValue& arg);
677 double Integral(const SpectrumValue& arg);
678 
679 } // namespace ns3
680 
681 #endif /* SPECTRUM_VALUE_H */
A template-based reference counting class.
size_t GetNumBands() const
Set of values corresponding to a given SpectrumModel.
friend SpectrumValue operator-(const SpectrumValue &lhs, const SpectrumValue &rhs)
subtraction operator
double & operator[](size_t index)
Access value at given frequency index.
void Subtract(const SpectrumValue &x)
Subtracts a SpectrumValue (element by element subtraction)
Values::const_iterator ConstValuesBegin() const
friend SpectrumValue operator+(const SpectrumValue &lhs, const SpectrumValue &rhs)
addition operator
friend double Prod(const SpectrumValue &x)
Bands::const_iterator ConstBandsEnd() const
void Divide(const SpectrumValue &x)
Divides by a SpectrumValue (element to element division)
friend double Norm(const SpectrumValue &x)
friend bool operator!=(const SpectrumValue &lhs, const SpectrumValue &rhs)
Compare two spectrum values.
friend double Integral(const SpectrumValue &arg)
SpectrumValue & operator=(double rhs)
Assign each component of *this to the value of the Right Hand Side of the operator.
Values::iterator ValuesBegin()
void Exp(double base)
Modifies each element so that it is the base raised to each element value.
Bands::const_iterator ConstBandsBegin() const
const Values & GetValues() const
Provides the direct read-only access to the underlying std::vector<double> that stores the spectrum v...
void ChangeSign()
Change the values sign.
void SetValues(Values &&values)
Directly set the values by moving the values from the input std::vector<double>
SpectrumValue operator<<(int n) const
left shift operator
void ShiftLeft(int n)
Shift the values to the left.
Ptr< SpectrumValue > Copy() const
friend SpectrumValue operator/(const SpectrumValue &lhs, const SpectrumValue &rhs)
division component-by-component
Values m_values
Set of values which implement the codomain of the functions in the Function Space defined by Spectrum...
uint32_t GetValuesN() const
Get the number of values stored in the array.
Values::iterator ValuesEnd()
Values & GetValues()
Provides the direct access to the underlying std::vector<double> that stores the spectrum values.
Ptr< const SpectrumModel > GetSpectrumModel() const
SpectrumValue & operator*=(const SpectrumValue &rhs)
Multiply *this by the Right Hand Side of the operator, component by component.
Ptr< const SpectrumModel > m_spectrumModel
The spectrum model.
friend bool operator==(const SpectrumValue &lhs, const SpectrumValue &rhs)
Compare two spectrum values.
void ShiftRight(int n)
Shift the values to the right.
friend SpectrumValue operator*(const SpectrumValue &lhs, const SpectrumValue &rhs)
multiplication component-by-component (Schur product)
void SetValues(Values &values)
Directly set the values using the std::vector<double>
friend double Sum(const SpectrumValue &x)
void Add(const SpectrumValue &x)
Add a SpectrumValue (element to element addition)
void Multiply(const SpectrumValue &x)
Multiplies for a SpectrumValue (element to element multiplication)
void Log()
Applies a Log to each the elements.
void Log2()
Applies a Log2 to each the elements.
SpectrumModelUid_t GetSpectrumModelUid() const
SpectrumValue & operator/=(const SpectrumValue &rhs)
Divide *this by the Right Hand Side of the operator, component by component.
SpectrumValue & operator+=(const SpectrumValue &rhs)
Add the Right Hand Side of the operator to *this, component by component.
Values::const_iterator ConstValuesEnd() const
SpectrumValue & operator-=(const SpectrumValue &rhs)
Subtract the Right Hand Side of the operator from *this, component by component.
SpectrumValue operator>>(int n) const
right shift operator
friend SpectrumValue Pow(const SpectrumValue &lhs, double rhs)
void Log10()
Applies a Log10 to each the elements.
const double & ValuesAt(uint32_t pos) const
Get the value element at the position.
Forward calls to a chain of Callback.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Every class exported by the ns3 library is enclosed in the ns3 namespace.
SpectrumValue Pow(double lhs, const SpectrumValue &rhs)
double Integral(const SpectrumValue &arg)
uint32_t SpectrumModelUid_t
Uid for SpectrumModels.
SpectrumValue Log2(const SpectrumValue &arg)
SpectrumValue Log10(const SpectrumValue &arg)
double Norm(const SpectrumValue &x)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
SpectrumValue Log(const SpectrumValue &arg)
double Prod(const SpectrumValue &x)
std::vector< double > Values
Container for element values.
double Sum(const SpectrumValue &x)