blob: 95d23475c4b965227c372fa429ebeae8b4a8d882 [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"
25
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070026#include <string>
Alexander Afanasyev070aa482011-08-20 00:38:25 -070027#include <algorithm>
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070028#include <list>
29
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070030namespace ns3 {
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070031namespace Name {
32
33class Components : public SimpleRefCount<Components>
34{
35public:
36 Components ();
37 Components (const std::string &s);
38 ~Components ();
39
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070040 inline void
41 Add (const std::string &s);
42
43 Components&
44 operator () (const std::string &s);
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070045
46 const std::list<std::string> &
47 GetComponents () const;
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070048
49 // virtual uint32_t
50 // GetSerializedSize (void) const;
51
52 // virtual void
53 // Serialize (Buffer::Iterator start) const;
54
55 // virtual uint32_t
56 // Deserialize (Buffer::Iterator start);
57
58 void Print (std::ostream &os) const;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070059
60 inline size_t
61 size () const;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070062
63 inline bool
64 operator== (const Components &prefix) const;
65
66 inline bool
67 operator< (const Components &prefix) const;
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070068
69private:
70 std::list<std::string> m_prefix;
71
72 typedef std::list<std::string>::iterator iterator;
73 typedef std::list<std::string>::const_iterator const_iterator;
74};
75
76std::ostream & operator << (std::ostream &os, const Components &components);
77
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070078size_t
79Components::size () const
80{
81 return m_prefix.size ();
82}
83
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070084void
85Components::Add (const std::string &s)
86{
87 (*this) (s);
88}
Alexander Afanasyev070aa482011-08-20 00:38:25 -070089
90bool
91Components::operator== (const Components &prefix) const
92{
93 return std::equal (m_prefix.begin (), m_prefix.end (), prefix.m_prefix.begin ());
94}
95
96bool
97Components::operator< (const Components &prefix) const
98{
99 return std::lexicographical_compare (m_prefix.begin (), m_prefix.end (),
100 prefix.m_prefix.begin (), prefix.m_prefix.end ());
101}
102
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -0700103} // Namespace Name
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -0700104} // namespace ns3
105
106#endif // _NDN_NAME_COMPONENTS_H_
107