Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 1 | /* -*- 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 NDN_CONTENT_STORE_IMPL_H_ |
| 22 | #define NDN_CONTENT_STORE_IMPL_H_ |
| 23 | |
| 24 | #include "ndn-content-store.h" |
| 25 | #include "ns3/packet.h" |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 26 | #include "ns3/ndn-interest.h" |
| 27 | #include "ns3/ndn-content-object.h" |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 28 | #include <boost/foreach.hpp> |
| 29 | |
Alexander Afanasyev | 1a2df6a | 2012-08-17 13:21:51 -0700 | [diff] [blame] | 30 | #include "../../utils/trie/trie-with-policy.h" |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 31 | |
| 32 | namespace ns3 { |
| 33 | namespace ndn { |
| 34 | namespace cs { |
| 35 | |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 36 | template<class CS> |
| 37 | class EntryImpl : public Entry |
| 38 | { |
| 39 | public: |
| 40 | EntryImpl (Ptr<const ContentObjectHeader> header, Ptr<const Packet> packet) |
| 41 | : Entry (header, packet) |
| 42 | , item_ (0) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | SetTrie (typename CS::super::iterator item) |
| 48 | { |
| 49 | item_ = item; |
| 50 | } |
| 51 | |
| 52 | typename CS::super::iterator to_iterator () { return item_; } |
| 53 | typename CS::super::const_iterator to_iterator () const { return item_; } |
| 54 | |
| 55 | private: |
| 56 | typename CS::super::iterator item_; |
| 57 | }; |
| 58 | |
| 59 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 60 | |
| 61 | template<class Policy> |
| 62 | class ContentStoreImpl : public ContentStore, |
| 63 | protected ndnSIM::trie_with_policy< NameComponents, |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 64 | ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > > >, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 65 | Policy > |
| 66 | { |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 67 | public: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 68 | typedef ndnSIM::trie_with_policy< NameComponents, |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 69 | ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > > >, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 70 | Policy > super; |
| 71 | |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 72 | typedef EntryImpl< ContentStoreImpl< Policy > > entry; |
| 73 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 74 | static TypeId |
| 75 | GetTypeId (); |
| 76 | |
| 77 | ContentStoreImpl () { }; |
| 78 | virtual ~ContentStoreImpl () { }; |
| 79 | |
| 80 | // from ContentStore |
| 81 | |
| 82 | virtual inline boost::tuple<Ptr<Packet>, Ptr<const ContentObjectHeader>, Ptr<const Packet> > |
| 83 | Lookup (Ptr<const InterestHeader> interest); |
| 84 | |
| 85 | virtual inline bool |
| 86 | Add (Ptr<const ContentObjectHeader> header, Ptr<const Packet> packet); |
| 87 | |
| 88 | // virtual bool |
| 89 | // Remove (Ptr<InterestHeader> header); |
| 90 | |
| 91 | virtual inline void |
| 92 | Print (std::ostream &os) const; |
| 93 | |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 94 | virtual uint32_t |
| 95 | GetSize () const; |
| 96 | |
| 97 | virtual Ptr<Entry> |
| 98 | Begin (); |
| 99 | |
| 100 | virtual Ptr<Entry> |
| 101 | End (); |
| 102 | |
| 103 | virtual Ptr<Entry> |
| 104 | Next (Ptr<Entry>); |
| 105 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 106 | private: |
| 107 | void |
| 108 | SetMaxSize (uint32_t maxSize); |
| 109 | |
| 110 | uint32_t |
| 111 | GetMaxSize () const; |
| 112 | }; |
| 113 | |
| 114 | } // namespace cs |
| 115 | } // namespace ndn |
| 116 | } // namespace ns3 |
| 117 | |
| 118 | #endif // NDN_CONTENT_STORE_IMPL_H_ |