control-response-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_CONTROL_RESPONSE_LITE_HPP
23 #define NDN_CONTROL_RESPONSE_LITE_HPP
24 
25 #include "control-parameters-lite.hpp"
26 #include "../c/control-response-types.h"
27 
28 namespace ndn {
29 
36 public:
55  (struct ndn_NameComponent *nameComponents, size_t maxNameComponents,
56  struct ndn_NameComponent *strategyNameComponents,
57  size_t strategyMaxNameComponents);
58 
59  int
60  getStatusCode() const { return statusCode; }
61 
62  const BlobLite&
63  getStatusText() const { return BlobLite::downCast(statusText); }
64 
69  bool
70  getHasBodyAsControlParameters() const { return hasBodyAsControlParameters != 0; }
71 
78  {
79  return ControlParametersLite::downCast(bodyAsControlParameters);
80  }
81 
84  {
85  return ControlParametersLite::downCast(bodyAsControlParameters);
86  }
87 
94  void
95  setHasBodyAsControlParameters(bool hasBodyAsControlParameters)
96  {
97  this->hasBodyAsControlParameters = hasBodyAsControlParameters ? 1 : 0;
98  }
99 
109  ndn_Error
110  setBodyAsControlParameters(const ControlParametersLite& bodyAsControlParameters)
111  {
112  hasBodyAsControlParameters = 1;
113  return ControlParametersLite::downCast(this->bodyAsControlParameters)
114  .set(bodyAsControlParameters);
115  }
116 
125  {
126  this->statusCode = statusCode;
127  return *this;
128  }
129 
138  {
139  BlobLite::downCast(this->statusText) = statusText;
140  return *this;
141  }
142 
149  static ControlResponseLite&
150  downCast(ndn_ControlResponse& controlResponse)
151  {
152  return *(ControlResponseLite*)&controlResponse;
153  }
154 
155  static const ControlResponseLite&
156  downCast(const ndn_ControlResponse& controlResponse)
157  {
158  return *(ControlResponseLite*)&controlResponse;
159  }
160 
161 private:
162  // Declare friends who can downcast to the private base.
163  friend class Tlv0_1_1WireFormatLite;
164 };
165 
166 }
167 
168 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
static ControlResponseLite & downCast(ndn_ControlResponse &controlResponse)
Downcast the reference to the ndn_ControlResponse struct to a ControlResponseLite.
Definition: control-response-lite.hpp:150
A ControlResponseLite holds a status code, status text and other fields for a ControlResponse which i...
Definition: control-response-lite.hpp:35
Copyright (C) 2016 Regents of the University of California.
Definition: control-response-types.h:35
struct ndn_Blob statusText
A Blob whose value is a pointer to pre-allocated buffer.
Definition: control-response-types.h:37
static BlobLite & downCast(ndn_Blob &blob)
Downcast the reference to the ndn_Blob struct to a BlobLite.
Definition: blob-lite.hpp:76
void setHasBodyAsControlParameters(bool hasBodyAsControlParameters)
Set the flag for whether the bodyAsControlParameters is specified.
Definition: control-response-lite.hpp:95
ndn_Error setBodyAsControlParameters(const ControlParametersLite &bodyAsControlParameters)
Set the bodyAsControlParameters to have the values from the given control parameters.
Definition: control-response-lite.hpp:110
ControlResponseLite & setStatusText(const BlobLite &statusText)
Set status text.
Definition: control-response-lite.hpp:137
Copyright (C) 2015-2016 Regents of the University of California.
Definition: name-types.h:33
static ControlParametersLite & downCast(ndn_ControlParameters &controlParameters)
Downcast the reference to the ndn_ControlParameters struct to a ControlParametersLite.
Definition: control-parameters-lite.hpp:253
ControlResponseLite(struct ndn_NameComponent *nameComponents, size_t maxNameComponents, struct ndn_NameComponent *strategyNameComponents, size_t strategyMaxNameComponents)
Create a ControlResponseLite to use the pre-allocated nameComponents and strategyNameComponents for t...
Definition: control-response-lite.cpp:28
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
A ControlParametersLite holds a Name and other fields for a ControlParameters which is used...
Definition: control-parameters-lite.hpp:37
ControlParametersLite & getBodyAsControlParameters()
Get the bodyAsControlParameters, if specified.
Definition: control-response-lite.hpp:77
bool getHasBodyAsControlParameters() const
Check if the bodyAsControlParameters is specified.
Definition: control-response-lite.hpp:70
ControlResponseLite & setStatusCode(int statusCode)
Set the status code.
Definition: control-response-lite.hpp:124
ndn_Error set(const ControlParametersLite &other)
Set this control parameters to have the values from the other control parameters. ...
Definition: control-parameters-lite.cpp:38
int statusCode
-1 for none.
Definition: control-response-types.h:36