Switch to unique_ptr for ownership clarity in places, combine more code.

This commit is contained in:
Ian Gulliver
2015-02-07 15:07:34 -08:00
parent 844db000f6
commit d82cb789e3
4 changed files with 56 additions and 71 deletions

6
tlv.cc
View File

@@ -43,7 +43,7 @@ void TLVNode::Encode(std::string *output) const {
}
}
TLVNode* TLVNode::Decode(const std::string& input) {
std::unique_ptr<TLVNode> TLVNode::Decode(const std::string& input) {
if (input.length() < sizeof(struct header)) {
return nullptr;
}
@@ -71,10 +71,10 @@ TLVNode* TLVNode::Decode(const std::string& input) {
cursor += sub_length;
}
return container.release();
return container;
} else {
// Scalar
return new TLVNode(htons(header->type), input.substr(sizeof(*header), htons(header->value_length)));
return std::unique_ptr<TLVNode>(new TLVNode(htons(header->type), input.substr(sizeof(*header), htons(header->value_length))));
}
}