blob: 55cd5ae19124b3eedf0c7aaf92d686930dbc2e5b [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -07002/*
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 Afanasyev2536e202011-08-12 14:13:10 -070024#include "ns3/simple-ref-count.h"
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070025#include "ns3/attribute.h"
26#include "ns3/attribute-helper.h"
Alexander Afanasyev2536e202011-08-12 14:13:10 -070027
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070028#include <string>
Alexander Afanasyev070aa482011-08-20 00:38:25 -070029#include <algorithm>
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070030#include <list>
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070031#include "ns3/object.h"
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070032
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070033namespace ns3 {
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070034
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070035class CcnxNameComponents : public Object
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070036
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070037{
38public:
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070039 CcnxNameComponents ();
40 CcnxNameComponents (const std::string &s);
41 ~CcnxNameComponents ();
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070042
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070043 inline void
44 Add (const std::string &s);
45
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070046 CcnxNameComponents&
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070047 operator () (const std::string &s);
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070048
49 const std::list<std::string> &
50 GetComponents () const;
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070051
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 Afanasyevc74a6022011-08-15 20:01:35 -070062
63 inline size_t
64 size () const;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070065
66 inline bool
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070067 operator== (const CcnxNameComponents &prefix) const;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070068
69 inline bool
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070070 operator< (const CcnxNameComponents &prefix) const;
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070071
72private:
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 Moiseenko2bd1bc32011-08-23 16:01:35 -070079std::ostream & operator << (std::ostream &os, const CcnxNameComponents &components);
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070080
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070081size_t
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070082CcnxNameComponents::size () const
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070083{
84 return m_prefix.size ();
85}
86
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070087void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070088CcnxNameComponents::Add (const std::string &s)
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070089{
90 (*this) (s);
91}
Alexander Afanasyev070aa482011-08-20 00:38:25 -070092
93bool
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070094CcnxNameComponents::operator== (const CcnxNameComponents &prefix) const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070095{
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070096 if (m_prefix.size () != prefix.m_prefix.size ())
97 return false;
98
Alexander Afanasyev070aa482011-08-20 00:38:25 -070099 return std::equal (m_prefix.begin (), m_prefix.end (), prefix.m_prefix.begin ());
100}
101
102bool
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700103CcnxNameComponents::operator< (const CcnxNameComponents &prefix) const
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700104{
105 return std::lexicographical_compare (m_prefix.begin (), m_prefix.end (),
106 prefix.m_prefix.begin (), prefix.m_prefix.end ());
107}
108
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700109
110/**
111* \class ns3::ComponentsValue
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700112* \brief hold objects of type ns3:CcnxNameComponents
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700113*/
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700114ATTRIBUTE_VALUE_DEFINE (CcnxNameComponents);
115ATTRIBUTE_ACCESSOR_DEFINE (CcnxNameComponents);
116ATTRIBUTE_CHECKER_DEFINE (CcnxNameComponents);
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -0700117} // namespace ns3
118
119#endif // _NDN_NAME_COMPONENTS_H_
120