-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Danpf/const map stuff #32
Conversation
I never really saw the need for diff --git a/include/mmtf/map_decoder.hpp b/include/mmtf/map_decoder.hpp
index ba77c44..0349ead 100644
--- a/include/mmtf/map_decoder.hpp
+++ b/include/mmtf/map_decoder.hpp
@@ -103,10 +103,24 @@ public:
* @brief Check if there are any keys, that were not decoded.
* This is to be called after all expected fields have been decoded.
* A warning is written to stderr for each non-decoded key.
+ *
+ * This is a no-op for const references.
*/
- void checkExtraKeys() const;
+ void checkExtraKeys();
+ void checkExtraKeys() const {};
private:
+
+ /**
+ * Remember that this key has been decoded (for checkExtraKeys).
+ *
+ * This is a no-op for const references.
+ */
+ void decoded_keys_insert(const std::string& key) {
+ decoded_keys_.insert(key);
+ }
+ void decoded_keys_insert(const std::string& key) const {}
+
// when constructed with byte buffer, we keep unpacked object
// NOTE: this contains a unique pointer to msgpack data (cannot copy)
msgpack::object_handle object_handle_;
@@ -114,7 +128,7 @@ private:
typedef std::map<std::string, const msgpack::object*> data_map_type_;
data_map_type_ data_map_;
// set of keys that were successfully decoded
- mutable std::set<std::string> decoded_keys_;
+ std::set<std::string> decoded_keys_;
/**
* @brief Initialize object given an object
@@ -174,7 +188,7 @@ inline MapDecoder::copy_decode(const std::string& key, bool required,
// note: cost of O(M*log(N)) string comparisons (M parsed, N in map)
data_map_type_::const_iterator it = data_map_.find(key);
if (it != data_map_.end()) {
- decoded_keys_.insert(key);
+ decoded_keys_insert(key);
// expensive copy here
msgpack::object tmp_object(*it->second, zone);
tmp_object.convert(target);
@@ -197,7 +211,7 @@ inline void MapDecoder::decode(const std::string& key, bool required, T& target)
} else {
it->second->convert(target);
}
- decoded_keys_.insert(key);
+ decoded_keys_insert(key);
}
else if (required) {
throw DecodeError("MsgPack MAP does not contain required entry "
@@ -205,8 +219,7 @@ inline void MapDecoder::decode(const std::string& key, bool required, T& target)
}
}
-
-inline void MapDecoder::checkExtraKeys() const {
+inline void MapDecoder::checkExtraKeys() {
// note: cost of O(N*log(M))) string comparisons (M parsed, N in map)
// simple set difference algorithm
data_map_type_::const_iterator map_it; |
I'm ok either way, but I think it sort of makes it a useless debugging tool if we're going to make it un-useable ~half the time. |
I didn't really think this through, sorry. If |
gotcha.... I've never actually used the debugging features of checkExtraKeys so i'd be fine getting rid of it. But i'm hesitant to do that, since someone might actually find it handy. |
As @speleo3 correctly pointed out, it was always just meant for debugging and development. Like this we are consistent with usual debugging in C++ (i.e. same as the |
I think it's fine the way it is now until someone explicitly wants/needs it gone. |
no strong opinion. I'm fine with the mutable. |
Anyone have any qualms with this?
the biggest problem is we now have a mutable... but i think that's preferable.
someone wanted to pass a decoder as const & and then they couldn't use decode :(