exclude-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_EXCLUDE_LITE_HPP
23 #define NDN_EXCLUDE_LITE_HPP
24 
25 #include "name-lite.hpp"
26 #include "../c/interest-types.h"
27 
28 namespace ndn {
29 
33 class ExcludeLite : private ndn_Exclude {
34 public:
44 
45  class Entry : private ndn_ExcludeEntry {
46  public:
50  Entry();
51 
58  Entry(const uint8_t *component, size_t componentLength);
59 
65  Entry(const BlobLite& component);
66 
67  ndn_ExcludeType
68  getType() const { return type; }
69 
70  const NameLite::Component&
71  getComponent() const { return NameLite::Component::downCast(component); }
72 
78  static Entry&
79  downCast(ndn_ExcludeEntry& entry) { return *(Entry*)&entry; }
80 
81  static const Entry&
82  downCast(const ndn_ExcludeEntry& entry) { return *(Entry*)&entry; }
83  };
84 
89  size_t
90  size() const { return nEntries; }
91 
97  const ExcludeLite::Entry&
98  get(size_t i) const
99  {
100  // TODO: Range check.
101  return Entry::downCast(entries[i]);
102  }
103 
109  ndn_Error
110  appendAny();
111 
120  ndn_Error
121  appendComponent(const uint8_t* component, size_t componentLength);
122 
131  ndn_Error
133  {
134  return appendComponent
135  (component.getValue().buf(), component.getValue().size());
136  }
137 
141  void
142  clear();
143 
150  ndn_Error
151  set(const ExcludeLite& other);
152 
158  static ExcludeLite&
159  downCast(ndn_Exclude& exclude) { return *(ExcludeLite*)&exclude; }
160 
161  static const ExcludeLite&
162  downCast(const ndn_Exclude& exclude) { return *(ExcludeLite*)&exclude; }
163 
164 private:
169  ExcludeLite(const ExcludeLite& other);
170 
175  ExcludeLite& operator=(const ExcludeLite& other);
176 };
177 
178 }
179 
180 #endif
An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the com...
Definition: interest-types.h:39
size_t size() const
Return size given to the constructor.
Definition: blob-lite.hpp:61
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
size_t nEntries
the number of entries in the exclude, 0 for no exclude
Definition: interest-types.h:50
size_t size() const
Get the number of entries.
Definition: exclude-lite.hpp:90
Entry()
Create an ExcludeLite::Entry of type ndn_Exclude_ANY.
Definition: exclude-lite.cpp:27
void clear()
Clear all the entries.
Definition: exclude-lite.cpp:62
struct ndn_ExcludeEntry * entries
pointer to the array of entries.
Definition: interest-types.h:48
static ExcludeLite & downCast(ndn_Exclude &exclude)
Downcast the reference to the ndn_Exclude struct to an ExcludeLite.
Definition: exclude-lite.hpp:159
ndn_Error appendComponent(const NameLite::Component &component)
Append a new entry of type ndn_Exclude_COMPONENT with the given component value.
Definition: exclude-lite.hpp:132
An ndn_Exclude holds an array of ndn_ExcludeEntry.
Definition: interest-types.h:47
An ExcludeLite holds an array of ExcludeLite::Entry.
Definition: exclude-lite.hpp:33
static Entry & downCast(ndn_ExcludeEntry &entry)
Downcast the reference to the ndn_ExcludeEntry struct to an ExcludeLite::Entry.
Definition: exclude-lite.hpp:79
A NameLite::Component holds a pointer to the component value.
Definition: name-lite.hpp:39
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
static Component & downCast(ndn_NameComponent &component)
Downcast the reference to the ndn_NameComponent struct to a NameLite::Component.
Definition: name-lite.hpp:220
const uint8_t * buf() const
Return buf given to the constructor.
Definition: blob-lite.hpp:55
ExcludeLite(ndn_ExcludeEntry *entries, size_t maxEntries)
Create an ExcludeLite with the entries array.
Definition: exclude-lite.cpp:44
size_t maxEntries
the number of elements in the allocated entries array
Definition: interest-types.h:49
Definition: exclude-lite.hpp:45
ndn_Error appendAny()
Append a new entry of type ndn_Exclude_ANY.
Definition: exclude-lite.cpp:50
ndn_Error appendComponent(const uint8_t *component, size_t componentLength)
Append a new entry of type ndn_Exclude_COMPONENT with the given component value.
Definition: exclude-lite.cpp:56
ndn_Error set(const ExcludeLite &other)
Set this exclude object to have the values from the other exclude.
Definition: exclude-lite.cpp:65