Use const where possible.
diff --git a/ndn-cpp/Interest.cpp b/ndn-cpp/Interest.cpp
index b99c3cd..d081620 100644
--- a/ndn-cpp/Interest.cpp
+++ b/ndn-cpp/Interest.cpp
@@ -30,7 +30,7 @@
(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 @@
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 @@
interestStruct.nonceLength = nonce_.size();
if (nonce_.size() > 0)
- interestStruct.nonce = &nonce_[0];
+ interestStruct.nonce = (unsigned char *)&nonce_[0];
else
interestStruct.nonce = 0;
}
diff --git a/ndn-cpp/Interest.hpp b/ndn-cpp/Interest.hpp
index 01681be..1d63db8 100644
--- a/ndn-cpp/Interest.hpp
+++ b/ndn-cpp/Interest.hpp
@@ -14,11 +14,11 @@
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 @@
* 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.
diff --git a/ndn-cpp/Name.cpp b/ndn-cpp/Name.cpp
index a5c8ade..f80d1a7 100644
--- a/ndn-cpp/Name.cpp
+++ b/ndn-cpp/Name.cpp
@@ -226,7 +226,7 @@
}
}
-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 @@
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 "/";
diff --git a/ndn-cpp/Name.hpp b/ndn-cpp/Name.hpp
index fbb28d0..0d43e93 100644
--- a/ndn-cpp/Name.hpp
+++ b/ndn-cpp/Name.hpp
@@ -29,9 +29,9 @@
* 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 @@
*/
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 @@
* 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 @@
* Get the number of components.
* @return the number of components
*/
- unsigned int getComponentCount() {
+ unsigned int getComponentCount() const {
return components_.size();
}
@@ -131,7 +131,7 @@
* Encode this name as a URI.
* @return the encoded URI.
*/
- std::string to_uri();
+ std::string to_uri() const;
private:
std::vector<NameComponent> components_;
diff --git a/ndn-cpp/encoding/BinaryXMLStructureDecoder.hpp b/ndn-cpp/encoding/BinaryXMLStructureDecoder.hpp
index ad562ff..8c39cf1 100644
--- a/ndn-cpp/encoding/BinaryXMLStructureDecoder.hpp
+++ b/ndn-cpp/encoding/BinaryXMLStructureDecoder.hpp
@@ -37,8 +37,8 @@
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_;
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
index a92237e..2cb6de6 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
@@ -17,7 +17,7 @@
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 @@
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];
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.hpp b/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
index 5b3d065..ad3a88c 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
@@ -12,10 +12,10 @@
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_; }
diff --git a/ndn-cpp/encoding/WireFormat.cpp b/ndn-cpp/encoding/WireFormat.cpp
index f3906fd..3217fe1 100644
--- a/ndn-cpp/encoding/WireFormat.cpp
+++ b/ndn-cpp/encoding/WireFormat.cpp
@@ -10,7 +10,7 @@
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 @@
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");
}
diff --git a/ndn-cpp/encoding/WireFormat.hpp b/ndn-cpp/encoding/WireFormat.hpp
index d9811cd..f09ae22 100644
--- a/ndn-cpp/encoding/WireFormat.hpp
+++ b/ndn-cpp/encoding/WireFormat.hpp
@@ -15,10 +15,10 @@
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.