Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "cs-entry-impl.hpp" |
| 27 | |
| 28 | namespace nfd { |
| 29 | namespace cs { |
| 30 | |
| 31 | EntryImpl::EntryImpl(const Name& name) |
| 32 | : m_queryName(name) |
| 33 | { |
| 34 | BOOST_ASSERT(this->isQuery()); |
| 35 | } |
| 36 | |
| 37 | EntryImpl::EntryImpl(shared_ptr<const Data> data, bool isUnsolicited) |
| 38 | : queueType(QUEUE_NONE) |
| 39 | { |
| 40 | this->setData(data, isUnsolicited); |
| 41 | BOOST_ASSERT(!this->isQuery()); |
| 42 | } |
| 43 | |
| 44 | bool |
| 45 | EntryImpl::isQuery() const |
| 46 | { |
| 47 | return !this->hasData(); |
| 48 | } |
| 49 | |
| 50 | bool |
| 51 | EntryImpl::canStale() const |
| 52 | { |
| 53 | BOOST_ASSERT(!this->isQuery()); |
| 54 | return this->getStaleTime() < time::steady_clock::TimePoint::max(); |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | EntryImpl::unsetUnsolicited() |
| 59 | { |
| 60 | BOOST_ASSERT(!this->isQuery()); |
| 61 | this->setData(this->getData(), false); |
| 62 | } |
| 63 | |
| 64 | bool |
| 65 | EntryImpl::operator<(const EntryImpl& other) const |
| 66 | { |
| 67 | if (this->isQuery()) { |
| 68 | if (other.isQuery()) { |
| 69 | return m_queryName < other.m_queryName; |
| 70 | } |
| 71 | else { |
| 72 | return m_queryName < other.m_queryName; |
| 73 | } |
| 74 | } |
| 75 | else { |
| 76 | if (other.isQuery()) { |
| 77 | return this->getFullName() < other.m_queryName; |
| 78 | } |
| 79 | else { |
| 80 | return this->getFullName() < other.getFullName(); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | } // namespace cs |
| 86 | } // namespace nfd |