blob: 1fb5ade32af495c108043930b897b95054be6fa8 [file] [log] [blame]
Yingdi Yu77627ab2015-07-21 16:13:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu0a312e52015-07-22 13:14:53 -07003 * Copyright (c) 2014-2015, Regents of the University of California.
Yingdi Yu77627ab2015-07-21 16:13:49 -07004 *
Yingdi Yu0a312e52015-07-22 13:14:53 -07005 * This file is part of ndn-tools (Named Data Networking Essential Tools).
6 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
Yingdi Yu77627ab2015-07-21 16:13:49 -07007 *
Yingdi Yu0a312e52015-07-22 13:14:53 -07008 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Yingdi Yu77627ab2015-07-21 16:13:49 -070011 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070012 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Yingdi Yu77627ab2015-07-21 16:13:49 -070015 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070016 * You should have received a copy of the GNU General Public License along with
17 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Yingdi Yu77627ab2015-07-21 16:13:49 -070018 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070019 * @author Yingdi Yu <yingdi@cs.ucla.edu>
Yingdi Yu77627ab2015-07-21 16:13:49 -070020 */
21
22#include "response-cache.hpp"
23
24namespace ndn {
25namespace pib {
26
27using std::map;
28
29ResponseCache::ResponseCache()
30{
31}
32
33
34shared_ptr<const Data>
35ResponseCache::find(const Name& dataName, bool hasVersion) const
36{
37 if (!hasVersion) {
38 Storage::const_iterator it = m_storage.find(dataName);
39 if (it != m_storage.end())
40 return it->second;
41 else
42 return shared_ptr<const Data>();
43 }
44 else {
45 Storage::const_iterator it = m_storage.find(dataName.getPrefix(-1));
46 if (it != m_storage.end() && it->second->getName() == dataName)
47 return it->second;
48 else
49 return shared_ptr<const Data>();
50 }
51}
52
53void
54ResponseCache::insert(const Data& data)
55{
56 data.getName().at(-1).toVersion(); // ensures last component is version
57 m_storage[data.getName().getPrefix(-1)] = data.shared_from_this();
58}
59
60void
61ResponseCache::erase(const Name& dataNameWithoutVersion)
62{
63 m_storage.erase(dataNameWithoutVersion);
64}
65
66void
67ResponseCache::clear()
68{
69 m_storage.clear();
70}
71
72} // namespace pib
73} // namespace ndn