// Imitate Exclude::set(const ExcludeLite& excludeLite). static void setExclude(PyObject* exclude, const ExcludeLite& excludeLite) { PyObjectRef ignoreResult1(PyObject_CallMethodObjArgs(exclude, str.clear, NULL)); for (size_t i = 0; i < excludeLite.size(); ++i) { const ExcludeLite::Entry& entry = excludeLite.get(i); if (entry.getType() == ndn_Exclude_COMPONENT) { PyObjectRef blob(makeBlob(entry.getComponent().getValue())); // Imitate Name::Component::set(const NameLite::Component& componentLite). if (entry.getComponent().isImplicitSha256Digest()) PyObjectRef ignoreResult2(PyObject_CallMethodObjArgs (exclude, str.appendImplicitSha256Digest, blob.obj, NULL)); else PyObjectRef ignoreResult3(PyObject_CallMethodObjArgs (exclude, str.appendComponent, blob.obj, NULL)); } else if (entry.getType() == ndn_Exclude_ANY) PyObjectRef ignoreResult3(PyObject_CallMethodObjArgs (exclude, str.appendAny, NULL)); else // unrecognized ndn_ExcludeType" // TODO: Handle the error! return; } }
void Exclude::set(const ExcludeLite& excludeLite) { clear(); for (size_t i = 0; i < excludeLite.size(); ++i) { const ExcludeLite::Entry& entry = excludeLite.get(i); if (entry.getType() == ndn_Exclude_COMPONENT) appendComponent(Name::Component(entry.getComponent())); else if (entry.getType() == ndn_Exclude_ANY) appendAny(); else throw runtime_error("unrecognized ndn_ExcludeType"); } }
void Exclude::get(ExcludeLite& excludeLite) const { excludeLite.clear(); for (size_t i = 0; i < entries_.size(); ++i) { ndn_Error error; if (entries_[i].getType() == ndn_Exclude_COMPONENT) { NameLite::Component component; entries_[i].getComponent().get(component); if ((error = excludeLite.appendComponent(component))) throw runtime_error(ndn_getErrorString(error)); } else { if ((error = excludeLite.appendAny())) throw runtime_error(ndn_getErrorString(error)); } } }
// Imitate Exclude::get(ExcludeLite& excludeLite). static void toExcludeLite(PyObject* exclude, ExcludeLite& excludeLite) { excludeLite.clear(); PyObjectRef entries(PyObject_GetAttr(exclude, str._entries)); for (size_t i = 0; i < PyList_GET_SIZE(entries.obj); ++i) { PyObject* entry = PyList_GET_ITEM(entries.obj, i); ndn_Error error; if (toLongByMethod(entry, str.getType) == Exclude_COMPONENT) { PyObjectRef component(PyObject_CallMethodObjArgs (entry, str.getComponent, NULL)); NameLite::Component componentLite; toNameComponentLite(component, componentLite); if ((error = excludeLite.appendComponent(componentLite))) // TODO: Handle the error! return; } else { if ((error = excludeLite.appendAny())) // TODO: Handle the error! return; } } }