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