src/spectrum/model/spectrum-type.cc
changeset 7841 2fe2efe0b4bc
parent 7840 2a669a0c452e
child 7842 b3edf14c5fcd
equal deleted inserted replaced
7840:2a669a0c452e 7841:2fe2efe0b4bc
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2010 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 #include "spectrum-type.h"
       
    22 #include <ns3/assert.h>
       
    23 
       
    24 
       
    25 namespace ns3 {
       
    26 
       
    27 
       
    28 
       
    29 std::vector<std::string> SpectrumTypeFactory::m_names;
       
    30 
       
    31 
       
    32 SpectrumType
       
    33 SpectrumTypeFactory::Create (std::string name)
       
    34 {
       
    35   std::vector<std::string>::iterator it;
       
    36   for (it = m_names.begin (); it != m_names.end (); ++it)
       
    37     {
       
    38       NS_ASSERT_MSG (name != *it, "name \"" << name << "\" already registered!");
       
    39     }
       
    40   m_names.push_back (name);
       
    41   return SpectrumType (m_names.size () - 1);
       
    42 }
       
    43 
       
    44 
       
    45 
       
    46 std::string
       
    47 SpectrumTypeFactory::GetNameByUid (uint32_t uid)
       
    48 {
       
    49   return m_names.at (uid);
       
    50 }
       
    51 
       
    52 
       
    53 
       
    54 SpectrumType::SpectrumType (uint32_t uid)
       
    55   : m_uid (uid)
       
    56 {
       
    57 }
       
    58 
       
    59 uint32_t
       
    60 SpectrumType::GetUid () const
       
    61 {
       
    62   return m_uid;
       
    63 }
       
    64 
       
    65 
       
    66 std::string
       
    67 SpectrumType::GetName () const
       
    68 {
       
    69   return SpectrumTypeFactory::GetNameByUid (m_uid);
       
    70 }
       
    71 
       
    72 
       
    73 bool
       
    74 operator== (const SpectrumType& lhs, const SpectrumType& rhs)
       
    75 {
       
    76   return (lhs.GetUid () == rhs.GetUid ());
       
    77 }
       
    78 
       
    79 
       
    80 bool
       
    81 operator!= (const SpectrumType& lhs, const SpectrumType& rhs)
       
    82 {
       
    83   return (lhs.GetUid () != rhs.GetUid ());
       
    84 }
       
    85 
       
    86 std::ostream&
       
    87 operator<<  (std::ostream& os, const SpectrumType& rhs)
       
    88 {
       
    89   os << rhs.GetName ();
       
    90   return os;
       
    91 }
       
    92 
       
    93 
       
    94 } // namespace ns3
       
    95