NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
cs-entry-impl.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "cs-entry-impl.hpp"
27 
28 namespace nfd {
29 namespace cs {
30 
32  : m_queryName(name)
33 {
34  BOOST_ASSERT(this->isQuery());
35 }
36 
37 EntryImpl::EntryImpl(shared_ptr<const Data> data, bool isUnsolicited)
38 {
39  this->setData(data, isUnsolicited);
40  BOOST_ASSERT(!this->isQuery());
41 }
42 
43 bool
44 EntryImpl::isQuery() const
45 {
46  return !this->hasData();
47 }
48 
49 void
51 {
52  BOOST_ASSERT(!this->isQuery());
53  this->setData(this->getData(), false);
54 }
55 
56 int
57 compareQueryWithData(const Name& queryName, const Data& data)
58 {
59  bool queryIsFullName = !queryName.empty() && queryName[-1].isImplicitSha256Digest();
60 
61  int cmp = queryIsFullName ?
62  queryName.compare(0, queryName.size() - 1, data.getName()) :
63  queryName.compare(data.getName());
64 
65  if (cmp != 0) { // Name without digest differs
66  return cmp;
67  }
68 
69  if (queryIsFullName) { // Name without digest equals, compare digest
70  return queryName[-1].compare(data.getFullName()[-1]);
71  }
72  else { // queryName is a proper prefix of Data fullName
73  return -1;
74  }
75 }
76 
77 int
78 compareDataWithData(const Data& lhs, const Data& rhs)
79 {
80  int cmp = lhs.getName().compare(rhs.getName());
81  if (cmp != 0) {
82  return cmp;
83  }
84 
85  return lhs.getFullName()[-1].compare(rhs.getFullName()[-1]);
86 }
87 
88 bool
89 EntryImpl::operator<(const EntryImpl& other) const
90 {
91  if (this->isQuery()) {
92  if (other.isQuery()) {
93  return m_queryName < other.m_queryName;
94  }
95  else {
96  return compareQueryWithData(m_queryName, other.getData()) < 0;
97  }
98  }
99  else {
100  if (other.isQuery()) {
101  return compareQueryWithData(other.m_queryName, this->getData()) > 0;
102  }
103  else {
104  return compareDataWithData(this->getData(), other.getData()) < 0;
105  }
106  }
107 }
108 
109 } // namespace cs
110 } // namespace nfd
bool hasData() const
Definition: cs-entry.hpp:107
void setData(shared_ptr< const Data > data, bool isUnsolicited)
replaces the stored Data
Definition: cs-entry.cpp:32
an Entry in ContentStore implementation
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
const Data & getData() const
Definition: cs-entry.hpp:43
bool isUnsolicited() const
Definition: cs-entry.hpp:73
size_t size() const
Get number of components.
Definition: name.hpp:154
Represents an absolute name.
Definition: name.hpp:42
bool operator<(const EntryImpl &other) const
const Name & getName() const
Get name.
Definition: data.hpp:121
int compare(const Name &other) const
Compare this to the other Name using NDN canonical ordering.
Definition: name.hpp:520
bool empty() const
Check if name is empty.
Definition: name.hpp:146
int compareQueryWithData(const Name &queryName, const Data &data)
const Name & getFullName() const
Get full name including implicit digest.
Definition: data.cpp:148
int compareDataWithData(const Data &lhs, const Data &rhs)
Represents a Data packet.
Definition: data.hpp:35
EntryImpl(const Name &name)
construct Entry for query