adjacency.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, The University of Memphis,
4  * Regents of the University of California,
5  * Arizona Board of Regents.
6  *
7  * This file is part of NLSR (Named-data Link State Routing).
8  * See AUTHORS.md for complete list of NLSR authors and contributors.
9  *
10  * NLSR is free software: you can redistribute it and/or modify it under the terms
11  * of the GNU General Public License as published by the Free Software Foundation,
12  * either version 3 of the License, or (at your option) any later version.
13  *
14  * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16  * PURPOSE. See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along with
19  * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef NLSR_TLV_ADJACENCY_HPP
23 #define NLSR_TLV_ADJACENCY_HPP
24 
25 #include <ndn-cxx/util/time.hpp>
26 #include <ndn-cxx/encoding/block.hpp>
27 #include <ndn-cxx/encoding/encoding-buffer.hpp>
28 #include <ndn-cxx/encoding/tlv.hpp>
29 #include <ndn-cxx/name.hpp>
30 
31 namespace nlsr {
32 namespace tlv {
33 
44 class Adjacency
45 {
46 public:
47  class Error : public ndn::tlv::Error
48  {
49  public:
50  explicit
51  Error(const std::string& what)
52  : ndn::tlv::Error(what)
53  {
54  }
55  };
56 
57  Adjacency();
58 
59  explicit
60  Adjacency(const ndn::Block& block);
61 
62  const ndn::Name&
63  getName() const
64  {
65  return m_name;
66  }
67 
68  Adjacency&
69  setName(const ndn::Name& name)
70  {
71  m_name = name;
72  m_wire.reset();
73  return *this;
74  }
75 
76  const std::string&
77  getUri() const
78  {
79  return m_uri;
80  }
81 
82  Adjacency&
83  setUri(const std::string& uri)
84  {
85  m_uri = uri;
86  m_wire.reset();
87  return *this;
88  }
89 
90  uint64_t
91  getCost() const
92  {
93  return m_cost;
94  }
95 
96  Adjacency&
97  setCost(uint64_t cost)
98  {
99  m_cost = cost;
100  m_wire.reset();
101  return *this;
102  }
103 
112  template<ndn::encoding::Tag TAG>
113  size_t
114  wireEncode(ndn::EncodingImpl<TAG>& block) const;
115 
123  const ndn::Block&
124  wireEncode() const;
125 
129  void
130  wireDecode(const ndn::Block& wire);
131 
132 private:
133  ndn::Name m_name;
134  std::string m_uri;
135  uint64_t m_cost;
136 
137  mutable ndn::Block m_wire;
138 };
139 
141 
142 std::ostream&
143 operator<<(std::ostream& os, const Adjacency& adjacency);
144 
145 } // namespace tlv
146 } // namespace nlsr
147 
148 #endif // NLSR_TLV_ADJACENCY_HPP
void wireDecode(const ndn::Block &wire)
Populate this object by decoding the object contained in the given block.
Definition: adjacency.cpp:86
Adjacency & setCost(uint64_t cost)
Definition: adjacency.hpp:97
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Definition: tlv-nlsr.hpp:28
const ndn::Block & wireEncode() const
Create a TLV encoding of this object.
Definition: adjacency.cpp:68
const std::string & getUri() const
Definition: adjacency.hpp:77
Adjacency & setUri(const std::string &uri)
Definition: adjacency.hpp:83
Error(const std::string &what)
Definition: adjacency.hpp:51
uint64_t getCost() const
Definition: adjacency.hpp:91
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const ndn::Name & getName() const
Definition: adjacency.hpp:63
std::ostream & operator<<(std::ostream &os, const AdjacencyLsa &adjacencyLsa)
Data abstraction for Adjacency.
Definition: adjacency.hpp:44
Adjacency & setName(const ndn::Name &name)
Definition: adjacency.hpp:69
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdjacencyLsa)