Browse Source

Added setVector in common.hpp

pull/1/head
Jeff Thompson 12 years ago
parent
commit
51dd5fd7fd
  1. 6
      ndn-cpp/Interest.cpp
  2. 8
      ndn-cpp/PublisherPublicKeyDigest.hpp
  3. 18
      ndn-cpp/common.hpp

6
ndn-cpp/Interest.cpp

@ -4,6 +4,7 @@
*/
#include <stdexcept>
#include "common.hpp"
#include "Interest.hpp"
using namespace std;
@ -48,10 +49,7 @@ void Interest::set(const struct ndn_Interest &interestStruct)
answerOriginKind_ = interestStruct.answerOriginKind;
scope_ = interestStruct.scope;
interestLifetime_ = interestStruct.interestLifetime;
nonce_.clear();
if (interestStruct.nonce)
nonce_.insert
(nonce_.begin(), interestStruct.nonce, interestStruct.nonce + interestStruct.nonceLength);
setVector(nonce_, interestStruct.nonce, interestStruct.nonceLength);
}
void Interest::get(struct ndn_Interest &interestStruct) const

8
ndn-cpp/PublisherPublicKeyDigest.hpp

@ -7,6 +7,7 @@
#define NDN_PUBLISHERPUBLICKEYDIGEST_HPP
#include <vector>
#include "common.hpp"
#include "c/PublisherPublicKeyDigest.h"
namespace ndn {
@ -40,11 +41,8 @@ public:
*/
void set(const struct ndn_PublisherPublicKeyDigest &publisherPublicKeyDigestStruct)
{
publisherPublicKeyDigest_.clear();
if (publisherPublicKeyDigestStruct.publisherPublicKeyDigest)
publisherPublicKeyDigest_.insert
(publisherPublicKeyDigest_.begin(), publisherPublicKeyDigestStruct.publisherPublicKeyDigest,
publisherPublicKeyDigestStruct.publisherPublicKeyDigest + publisherPublicKeyDigestStruct.publisherPublicKeyDigestLength);
setVector(publisherPublicKeyDigest_, publisherPublicKeyDigestStruct.publisherPublicKeyDigest,
publisherPublicKeyDigestStruct.publisherPublicKeyDigestLength);
}
const std::vector<unsigned char> &getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }

18
ndn-cpp/common.hpp

@ -6,6 +6,7 @@
#ifndef NDN_COMMON_HPP
#define NDN_COMMON_HPP
#include <vector>
#include "../config.h"
// Depending on where ./configure found shared_ptr, define the ptr_lib namespace.
@ -21,4 +22,21 @@ namespace ndn { namespace ptr_lib = boost; }
#error "Can't find shared_ptr in std or boost"
#endif
namespace ndn {
/**
* Clear the vector and copy valueLength bytes from value.
* @param v the vector to copy to
* @param value the array of bytes, or 0 to not copy
* @param valueLength the length of value
*/
static inline void setVector(std::vector<unsigned char> &vec, const unsigned char *value, unsigned int valueLength)
{
vec.clear();
if (value)
vec.insert(vec.begin(), value, value + valueLength);
}
}
#endif

Loading…
Cancel
Save