name-lsa.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NLSR_TLV_NAME_LSA_HPP
23 #define NLSR_TLV_NAME_LSA_HPP
24 
25 #include "lsa-info.hpp"
26 
27 #include <ndn-cxx/util/time.hpp>
28 #include <ndn-cxx/encoding/block.hpp>
29 #include <ndn-cxx/encoding/encoding-buffer.hpp>
30 #include <ndn-cxx/encoding/tlv.hpp>
31 #include <ndn-cxx/name.hpp>
32 
33 #include <list>
34 
35 namespace nlsr {
36 namespace tlv {
37 
47 class NameLsa
48 {
49 public:
50  class Error : public ndn::tlv::Error
51  {
52  public:
53  explicit
54  Error(const std::string& what)
55  : ndn::tlv::Error(what)
56  {
57  }
58  };
59 
60  typedef std::list<ndn::Name> NameList;
61  typedef NameList::const_iterator iterator;
62 
63  NameLsa();
64 
65  explicit
66  NameLsa(const ndn::Block& block);
67 
68  const LsaInfo&
69  getLsaInfo() const
70  {
71  return m_lsaInfo;
72  }
73 
74  NameLsa&
75  setLsaInfo(const LsaInfo& lsaInfo)
76  {
77  m_lsaInfo = lsaInfo;
78  m_wire.reset();
79  return *this;
80  }
81 
82  bool
83  hasNames() const
84  {
85  return m_hasNames;
86  }
87 
88  const std::list<ndn::Name>&
89  getNames() const
90  {
91  return m_names;
92  }
93 
94  NameLsa&
95  addName(const ndn::Name& name)
96  {
97  m_names.push_back(name);
98  m_wire.reset();
99  m_hasNames = true;
100  return *this;
101  }
102 
103  NameLsa&
105  {
106  m_names.clear();
107  m_hasNames = false;
108  return *this;
109  }
110 
120  template<ndn::encoding::Tag TAG>
121  size_t
122  wireEncode(ndn::EncodingImpl<TAG>& block) const;
123 
132  const ndn::Block&
133  wireEncode() const;
134 
138  void
139  wireDecode(const ndn::Block& wire);
140 
141  iterator
142  begin() const;
143 
144  iterator
145  end() const;
146 
147 private:
148  LsaInfo m_lsaInfo;
149  bool m_hasNames;
150  NameList m_names;
151 
152  mutable ndn::Block m_wire;
153 };
154 
155 inline NameLsa::iterator
157 {
158  return m_names.begin();
159 }
160 
161 inline NameLsa::iterator
163 {
164  return m_names.end();
165 }
166 
167 std::ostream&
168 operator<<(std::ostream& os, const NameLsa& nameLsa);
169 
170 } // namespace tlv
171 } // namespace nlsr
172 
173 #endif // NLSR_TLV_NAME_LSA_HPP
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Definition: tlv-nlsr.hpp:27
void wireDecode(const ndn::Block &wire)
Populate this object by decoding the one contained in the given block.
Definition: name-lsa.cpp:90
const std::list< ndn::Name > & getNames() const
Definition: name-lsa.hpp:89
NameLsa & addName(const ndn::Name &name)
Definition: name-lsa.hpp:95
NameLsa & setLsaInfo(const LsaInfo &lsaInfo)
Definition: name-lsa.hpp:75
NameList::const_iterator iterator
Definition: name-lsa.hpp:61
Error(const std::string &what)
Definition: name-lsa.hpp:54
iterator begin() const
Definition: name-lsa.hpp:156
Data abstraction for NameLsa.
Definition: name-lsa.hpp:47
bool hasNames() const
Definition: name-lsa.hpp:83
Data abstraction for LsaInfo.
Definition: lsa-info.hpp:47
NameLsa & clearNames()
Definition: name-lsa.hpp:104
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const LsaInfo & getLsaInfo() const
Definition: name-lsa.hpp:69
iterator end() const
Definition: name-lsa.hpp:162
std::ostream & operator<<(std::ostream &os, const AdjacencyLsa &adjacencyLsa)
const ndn::Block & wireEncode() const
Create a TLV encoding of this object.
Definition: name-lsa.cpp:72
std::list< ndn::Name > NameList
Definition: name-lsa.hpp:60