Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef _NDN_NAME_COMPONENTS_H_ |
| 22 | #define _NDN_NAME_COMPONENTS_H_ |
| 23 | |
Alexander Afanasyev | 2536e20 | 2011-08-12 14:13:10 -0700 | [diff] [blame] | 24 | #include "ns3/simple-ref-count.h" |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame^] | 25 | #include "ns3/attribute.h" |
| 26 | #include "ns3/attribute-helper.h" |
Alexander Afanasyev | 2536e20 | 2011-08-12 14:13:10 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 28 | #include <string> |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 29 | #include <algorithm> |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 30 | #include <list> |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame^] | 31 | #include "ns3/object.h" |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 33 | namespace ns3 { |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 34 | namespace Name { |
| 35 | |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame^] | 36 | class Components : public Object |
| 37 | |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 38 | { |
| 39 | public: |
| 40 | Components (); |
| 41 | Components (const std::string &s); |
| 42 | ~Components (); |
| 43 | |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 44 | inline void |
| 45 | Add (const std::string &s); |
| 46 | |
| 47 | Components& |
| 48 | operator () (const std::string &s); |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 49 | |
| 50 | const std::list<std::string> & |
| 51 | GetComponents () const; |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 52 | |
| 53 | // virtual uint32_t |
| 54 | // GetSerializedSize (void) const; |
| 55 | |
| 56 | // virtual void |
| 57 | // Serialize (Buffer::Iterator start) const; |
| 58 | |
| 59 | // virtual uint32_t |
| 60 | // Deserialize (Buffer::Iterator start); |
| 61 | |
| 62 | void Print (std::ostream &os) const; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 63 | |
| 64 | inline size_t |
| 65 | size () const; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 66 | |
| 67 | inline bool |
| 68 | operator== (const Components &prefix) const; |
| 69 | |
| 70 | inline bool |
| 71 | operator< (const Components &prefix) const; |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | std::list<std::string> m_prefix; |
| 75 | |
| 76 | typedef std::list<std::string>::iterator iterator; |
| 77 | typedef std::list<std::string>::const_iterator const_iterator; |
| 78 | }; |
| 79 | |
| 80 | std::ostream & operator << (std::ostream &os, const Components &components); |
| 81 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 82 | size_t |
| 83 | Components::size () const |
| 84 | { |
| 85 | return m_prefix.size (); |
| 86 | } |
| 87 | |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 88 | void |
| 89 | Components::Add (const std::string &s) |
| 90 | { |
| 91 | (*this) (s); |
| 92 | } |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 93 | |
| 94 | bool |
| 95 | Components::operator== (const Components &prefix) const |
| 96 | { |
| 97 | return std::equal (m_prefix.begin (), m_prefix.end (), prefix.m_prefix.begin ()); |
| 98 | } |
| 99 | |
| 100 | bool |
| 101 | Components::operator< (const Components &prefix) const |
| 102 | { |
| 103 | return std::lexicographical_compare (m_prefix.begin (), m_prefix.end (), |
| 104 | prefix.m_prefix.begin (), prefix.m_prefix.end ()); |
| 105 | } |
| 106 | |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame^] | 107 | |
| 108 | /** |
| 109 | * \class ns3::ComponentsValue |
| 110 | * \brief hold objects of type ns3::Name::Components |
| 111 | */ |
| 112 | ATTRIBUTE_VALUE_DEFINE (Components); |
| 113 | ATTRIBUTE_ACCESSOR_DEFINE (Components); |
| 114 | ATTRIBUTE_CHECKER_DEFINE (Components); |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 115 | } // Namespace Name |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 116 | } // namespace ns3 |
| 117 | |
| 118 | #endif // _NDN_NAME_COMPONENTS_H_ |
| 119 | |