blob: 5749fcce4325dec773e283bd843b586568807555 [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 -070034namespace Name {
35
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070036class Components : public Object
37
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070038{
39public:
40 Components ();
41 Components (const std::string &s);
42 ~Components ();
43
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070044 inline void
45 Add (const std::string &s);
46
47 Components&
48 operator () (const std::string &s);
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070049
50 const std::list<std::string> &
51 GetComponents () const;
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070052
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 Afanasyevc74a6022011-08-15 20:01:35 -070063
64 inline size_t
65 size () const;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070066
67 inline bool
68 operator== (const Components &prefix) const;
69
70 inline bool
71 operator< (const Components &prefix) const;
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070072
73private:
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
80std::ostream & operator << (std::ostream &os, const Components &components);
81
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070082size_t
83Components::size () const
84{
85 return m_prefix.size ();
86}
87
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070088void
89Components::Add (const std::string &s)
90{
91 (*this) (s);
92}
Alexander Afanasyev070aa482011-08-20 00:38:25 -070093
94bool
95Components::operator== (const Components &prefix) const
96{
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070097 if (m_prefix.size () != prefix.m_prefix.size ())
98 return false;
99
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700100 return std::equal (m_prefix.begin (), m_prefix.end (), prefix.m_prefix.begin ());
101}
102
103bool
104Components::operator< (const Components &prefix) const
105{
106 return std::lexicographical_compare (m_prefix.begin (), m_prefix.end (),
107 prefix.m_prefix.begin (), prefix.m_prefix.end ());
108}
109
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700110
111/**
112* \class ns3::ComponentsValue
113* \brief hold objects of type ns3::Name::Components
114*/
115ATTRIBUTE_VALUE_DEFINE (Components);
116ATTRIBUTE_ACCESSOR_DEFINE (Components);
117ATTRIBUTE_CHECKER_DEFINE (Components);
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -0700118} // Namespace Name
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -0700119} // namespace ns3
120
121#endif // _NDN_NAME_COMPONENTS_H_
122