Browse Source

Use const where possible.

pull/1/head
Jeff Thompson 12 years ago
parent
commit
d345a5b8bf
  1. 6
      ndn-cpp/Interest.cpp
  2. 14
      ndn-cpp/Interest.hpp
  3. 4
      ndn-cpp/Name.cpp
  4. 14
      ndn-cpp/Name.hpp
  5. 4
      ndn-cpp/encoding/BinaryXMLStructureDecoder.hpp
  6. 4
      ndn-cpp/encoding/BinaryXMLWireFormat.cpp
  7. 4
      ndn-cpp/encoding/BinaryXMLWireFormat.hpp
  8. 4
      ndn-cpp/encoding/WireFormat.cpp
  9. 4
      ndn-cpp/encoding/WireFormat.hpp

6
ndn-cpp/Interest.cpp

@ -30,7 +30,7 @@ void Interest::set(struct ndn_Interest &interestStruct)
(nonce_.begin(), interestStruct.nonce, interestStruct.nonce + interestStruct.nonceLength);
}
void Interest::get(struct ndn_Interest &interestStruct)
void Interest::get(struct ndn_Interest &interestStruct) const
{
name_.get(interestStruct.name);
interestStruct.minSuffixComponents = minSuffixComponents_;
@ -38,7 +38,7 @@ void Interest::get(struct ndn_Interest &interestStruct)
interestStruct.publisherPublicKeyDigestLength = publisherPublicKeyDigest_.size();
if (publisherPublicKeyDigest_.size() > 0)
interestStruct.publisherPublicKeyDigest = &publisherPublicKeyDigest_[0];
interestStruct.publisherPublicKeyDigest = (unsigned char *)&publisherPublicKeyDigest_[0];
else
interestStruct.publisherPublicKeyDigest = 0;
@ -51,7 +51,7 @@ void Interest::get(struct ndn_Interest &interestStruct)
interestStruct.nonceLength = nonce_.size();
if (nonce_.size() > 0)
interestStruct.nonce = &nonce_[0];
interestStruct.nonce = (unsigned char *)&nonce_[0];
else
interestStruct.nonce = 0;
}

14
ndn-cpp/Interest.hpp

@ -14,11 +14,11 @@ namespace ndn {
class Interest {
public:
void encode(std::vector<unsigned char> &output, WireFormat &wireFormat)
void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) const
{
wireFormat.encodeInterest(*this, output);
}
void encode(std::vector<unsigned char> &output)
void encode(std::vector<unsigned char> &output) const
{
encode(output, BinaryXMLWireFormat::instance());
}
@ -44,11 +44,15 @@ public:
* WARNING: The resulting pointers in interestStruct are invalid after a further use of this object which could reallocate memory.
* @param interestStruct a C ndn_Interest struct where the name components array is already allocated.
*/
void get(struct ndn_Interest &interestStruct);
void get(struct ndn_Interest &interestStruct) const;
Name &getName() { return name_; }
const Name &getName() const { return name_; }
int getInterestLifetime() { return interestLifetime_; }
int getMinSuffixComponents() const { return minSuffixComponents_; }
int getMaxSuffixComponents() const { return maxSuffixComponents_; }
int getInterestLifetime() const { return interestLifetime_; }
/**
* Clear this interest, and set the values by copying from the interest struct.

4
ndn-cpp/Name.cpp

@ -226,7 +226,7 @@ Name::Name(const char *uri_cstr)
}
}
void Name::get(struct ndn_Name &nameStruct)
void Name::get(struct ndn_Name &nameStruct) const
{
if (nameStruct.maxComponents < components_.size())
throw runtime_error("nameStruct.maxComponents must be >= this name getNComponents()");
@ -243,7 +243,7 @@ void Name::set(struct ndn_Name &nameStruct)
addComponent(nameStruct.components[i].value, nameStruct.components[i].valueLength);
}
std::string Name::to_uri()
std::string Name::to_uri() const
{
if (components_.size() == 0)
return "/";

14
ndn-cpp/Name.hpp

@ -29,9 +29,9 @@ public:
* WARNING: The resulting pointer in componentStruct is invalid after a further use of this object which could reallocate memory.
* @param componentStruct the C ndn_NameComponent struct to receive the pointer.
*/
void get(struct ndn_NameComponent &componentStruct)
void get(struct ndn_NameComponent &componentStruct) const
{
componentStruct.value = &value_[0];
componentStruct.value = (unsigned char *)&value_[0];
componentStruct.valueLength = value_.size();
}
@ -65,11 +65,11 @@ public:
*/
Name(const char *uri);
void encode(std::vector<unsigned char> &output, WireFormat &wireFormat)
void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) const
{
wireFormat.encodeName(*this, output);
}
void encode(std::vector<unsigned char> &output)
void encode(std::vector<unsigned char> &output) const
{
encode(output, BinaryXMLWireFormat::instance());
}
@ -95,7 +95,7 @@ public:
* WARNING: The resulting pointers in nameStruct are invalid after a further use of this object which could reallocate memory.
* @param nameStruct a C ndn_Name struct where the components array is already allocated.
*/
void get(struct ndn_Name &nameStruct);
void get(struct ndn_Name &nameStruct) const;
/**
* Clear this name, and set the components by copying from the name struct.
@ -121,7 +121,7 @@ public:
* Get the number of components.
* @return the number of components
*/
unsigned int getComponentCount() {
unsigned int getComponentCount() const {
return components_.size();
}
@ -131,7 +131,7 @@ public:
* Encode this name as a URI.
* @return the encoded URI.
*/
std::string to_uri();
std::string to_uri() const;
private:
std::vector<NameComponent> components_;

4
ndn-cpp/encoding/BinaryXMLStructureDecoder.hpp

@ -37,8 +37,8 @@ public:
return gotElementEnd();
}
unsigned int getOffset() { return base_.offset; }
bool gotElementEnd() { return base_.gotElementEnd != 0; }
unsigned int getOffset() const { return base_.offset; }
bool gotElementEnd() const { return base_.gotElementEnd != 0; }
private:
struct ndn_BinaryXMLStructureDecoder base_;

4
ndn-cpp/encoding/BinaryXMLWireFormat.cpp

@ -17,7 +17,7 @@ namespace ndn {
BinaryXMLWireFormat BinaryXMLWireFormat::instance_;
void BinaryXMLWireFormat::encodeName(Name &name, vector<unsigned char> &output)
void BinaryXMLWireFormat::encodeName(const Name &name, vector<unsigned char> &output)
{
struct ndn_Name nameStruct;
struct ndn_NameComponent components[100];
@ -46,7 +46,7 @@ void BinaryXMLWireFormat::decodeName(Name &name, const unsigned char *input, uns
name.set(nameStruct);
}
void BinaryXMLWireFormat::encodeInterest(Interest &interest, vector<unsigned char> &output)
void BinaryXMLWireFormat::encodeInterest(const Interest &interest, vector<unsigned char> &output)
{
struct ndn_Interest interestStruct;
struct ndn_NameComponent components[100];

4
ndn-cpp/encoding/BinaryXMLWireFormat.hpp

@ -12,10 +12,10 @@ namespace ndn {
class BinaryXMLWireFormat : public WireFormat {
public:
virtual void encodeName(Name &name, std::vector<unsigned char> &output);
virtual void encodeName(const Name &name, std::vector<unsigned char> &output);
virtual void decodeName(Name &name, const unsigned char *input, unsigned int inputLength);
virtual void encodeInterest(Interest &interest, std::vector<unsigned char> &output);
virtual void encodeInterest(const Interest &interest, std::vector<unsigned char> &output);
virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
static BinaryXMLWireFormat &instance() { return instance_; }

4
ndn-cpp/encoding/WireFormat.cpp

@ -10,7 +10,7 @@ using namespace std;
namespace ndn {
void WireFormat::encodeName(Name &name, vector<unsigned char> &output)
void WireFormat::encodeName(const Name &name, vector<unsigned char> &output)
{
throw logic_error("unimplemented");
}
@ -19,7 +19,7 @@ void WireFormat::decodeName(Name &name, const unsigned char *input, unsigned int
throw logic_error("unimplemented");
}
void WireFormat::encodeInterest(Interest &interest, vector<unsigned char> &output)
void WireFormat::encodeInterest(const Interest &interest, vector<unsigned char> &output)
{
throw logic_error("unimplemented");
}

4
ndn-cpp/encoding/WireFormat.hpp

@ -15,10 +15,10 @@ class Interest;
class WireFormat {
public:
virtual void encodeName(Name &name, std::vector<unsigned char> &output);
virtual void encodeName(const Name &name, std::vector<unsigned char> &output);
virtual void decodeName(Name &name, const unsigned char *input, unsigned int inputLength);
virtual void encodeInterest(Interest &interest, std::vector<unsigned char> &output);
virtual void encodeInterest(const Interest &interest, std::vector<unsigned char> &output);
virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
// etc. for each type of object.

Loading…
Cancel
Save