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 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 35 | class CcnxNameComponents : public Object |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 37 | { |
| 38 | public: |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 39 | CcnxNameComponents (); |
| 40 | CcnxNameComponents (const std::string &s); |
| 41 | ~CcnxNameComponents (); |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 42 | |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 43 | inline void |
| 44 | Add (const std::string &s); |
| 45 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 46 | CcnxNameComponents& |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 47 | operator () (const std::string &s); |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 48 | |
| 49 | const std::list<std::string> & |
| 50 | GetComponents () const; |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 51 | |
| 52 | // virtual uint32_t |
| 53 | // GetSerializedSize (void) const; |
| 54 | |
| 55 | // virtual void |
| 56 | // Serialize (Buffer::Iterator start) const; |
| 57 | |
| 58 | // virtual uint32_t |
| 59 | // Deserialize (Buffer::Iterator start); |
| 60 | |
| 61 | void Print (std::ostream &os) const; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 62 | |
| 63 | inline size_t |
| 64 | size () const; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 65 | |
| 66 | inline bool |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 67 | operator== (const CcnxNameComponents &prefix) const; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 68 | |
| 69 | inline bool |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 70 | operator< (const CcnxNameComponents &prefix) const; |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | std::list<std::string> m_prefix; |
| 74 | |
| 75 | typedef std::list<std::string>::iterator iterator; |
| 76 | typedef std::list<std::string>::const_iterator const_iterator; |
| 77 | }; |
| 78 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 79 | std::ostream & operator << (std::ostream &os, const CcnxNameComponents &components); |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 80 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 81 | size_t |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 82 | CcnxNameComponents::size () const |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 83 | { |
| 84 | return m_prefix.size (); |
| 85 | } |
| 86 | |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 87 | void |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 88 | CcnxNameComponents::Add (const std::string &s) |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 89 | { |
| 90 | (*this) (s); |
| 91 | } |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 92 | |
| 93 | bool |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 94 | CcnxNameComponents::operator== (const CcnxNameComponents &prefix) const |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 95 | { |
Alexander Afanasyev | fccdb9e | 2011-08-22 19:27:14 -0700 | [diff] [blame] | 96 | if (m_prefix.size () != prefix.m_prefix.size ()) |
| 97 | return false; |
| 98 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 99 | return std::equal (m_prefix.begin (), m_prefix.end (), prefix.m_prefix.begin ()); |
| 100 | } |
| 101 | |
| 102 | bool |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 103 | CcnxNameComponents::operator< (const CcnxNameComponents &prefix) const |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 104 | { |
| 105 | return std::lexicographical_compare (m_prefix.begin (), m_prefix.end (), |
| 106 | prefix.m_prefix.begin (), prefix.m_prefix.end ()); |
| 107 | } |
| 108 | |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * \class ns3::ComponentsValue |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 112 | * \brief hold objects of type ns3:CcnxNameComponents |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 113 | */ |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 114 | ATTRIBUTE_VALUE_DEFINE (CcnxNameComponents); |
| 115 | ATTRIBUTE_ACCESSOR_DEFINE (CcnxNameComponents); |
| 116 | ATTRIBUTE_CHECKER_DEFINE (CcnxNameComponents); |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 117 | } // namespace ns3 |
| 118 | |
| 119 | #endif // _NDN_NAME_COMPONENTS_H_ |
| 120 | |