blob: 55cd5ae19124b3eedf0c7aaf92d686930dbc2e5b [file] [log] [blame]
Ilya Moiseenkod26e6822011-08-23 17:48:38 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
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
24#include "ns3/simple-ref-count.h"
25#include "ns3/attribute.h"
26#include "ns3/attribute-helper.h"
27
28#include <string>
29#include <algorithm>
30#include <list>
31#include "ns3/object.h"
32
33namespace ns3 {
34
35class CcnxNameComponents : public Object
36
37{
38public:
39 CcnxNameComponents ();
40 CcnxNameComponents (const std::string &s);
41 ~CcnxNameComponents ();
42
43 inline void
44 Add (const std::string &s);
45
46 CcnxNameComponents&
47 operator () (const std::string &s);
48
49 const std::list<std::string> &
50 GetComponents () const;
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;
62
63 inline size_t
64 size () const;
65
66 inline bool
67 operator== (const CcnxNameComponents &prefix) const;
68
69 inline bool
70 operator< (const CcnxNameComponents &prefix) const;
71
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
79std::ostream & operator << (std::ostream &os, const CcnxNameComponents &components);
80
81size_t
82CcnxNameComponents::size () const
83{
84 return m_prefix.size ();
85}
86
87void
88CcnxNameComponents::Add (const std::string &s)
89{
90 (*this) (s);
91}
92
93bool
94CcnxNameComponents::operator== (const CcnxNameComponents &prefix) const
95{
96 if (m_prefix.size () != prefix.m_prefix.size ())
97 return false;
98
99 return std::equal (m_prefix.begin (), m_prefix.end (), prefix.m_prefix.begin ());
100}
101
102bool
103CcnxNameComponents::operator< (const CcnxNameComponents &prefix) const
104{
105 return std::lexicographical_compare (m_prefix.begin (), m_prefix.end (),
106 prefix.m_prefix.begin (), prefix.m_prefix.end ());
107}
108
109
110/**
111* \class ns3::ComponentsValue
112* \brief hold objects of type ns3:CcnxNameComponents
113*/
114ATTRIBUTE_VALUE_DEFINE (CcnxNameComponents);
115ATTRIBUTE_ACCESSOR_DEFINE (CcnxNameComponents);
116ATTRIBUTE_CHECKER_DEFINE (CcnxNameComponents);
117} // namespace ns3
118
119#endif // _NDN_NAME_COMPONENTS_H_
120