blob: 7db278b3f21896466d13e3c4b8f1b94a784e14ca [file] [log] [blame]
Alexander Afanasyev36b45772012-07-10 16:57:42 -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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21#ifndef PAYLOAD_WITH_INDEX_H_
22#define PAYLOAD_WITH_INDEX_H_
23
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070024namespace ns3 {
25namespace ndn {
26namespace ndnSIM {
Alexander Afanasyev36b45772012-07-10 16:57:42 -070027
28template<typename PayloadTraits,
29 typename IndexTraits>
30class payload_with_index
31{
32public:
33 typedef PayloadTraits::pointer_type iterator;
34
35 typedef typename IndexTraits::template index<
36 PayloadTraits,
37 typename IndexTraits::template container_hook<parent_trie>::type >::type index_container;
38
39 inline
40 payload_with_index ()
41 : index_ (*this)
42 {
43 }
44
45 inline std::pair< iterator, bool >
46 insert (typename iterator payload)
47 {
48 bool ok = policy_.insert (s_iterator_to (item.first));
49 if (!ok)
50 {
51 item.first->erase (); // cannot insert
52 return std::make_pair (end (), false);
53 }
54
55 return item;
56 }
57
58 // inline void
59 // erase (const FullKey &key)
60 // {
61 // iterator foundItem, lastItem;
62 // bool reachLast;
63 // boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
64
65 // if (!reachLast || lastItem->payload () == PayloadTraits::empty_payload)
66 // return; // nothing to invalidate
67
68 // erase (lastItem);
69 // }
70
71 // inline void
72 // erase (iterator node)
73 // {
74 // if (node == end ()) return;
75
76 // policy_.erase (s_iterator_to (node));
77 // node->erase (); // will do cleanup here
78 // }
79
80 // inline void
81 // clear ()
82 // {
83 // policy_.clear ();
84 // trie_.clear ();
85 // }
86
87 // template<typename Modifier>
88 // bool
89 // modify (iterator position, Modifier mod)
90 // {
91 // if (position == end ()) return false;
92 // if (position->payload () == PayloadTraits::empty_payload) return false;
93
94 // mod (*position->payload ());
95 // policy_.update (position);
96 // return true;
97 // }
98
99private:
100 mutable index_container policy_;
101};
102
103} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700104} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -0700105} // ns3
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700106
107#endif // PAYLOAD_WITH_POLICY_H_