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