mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Removed comparison/implicit conversion operators for Node, and renamed Node::Read<T>() to Node::to<T>()
This commit is contained in:
@@ -62,10 +62,7 @@ namespace YAML
|
||||
bool Read(T& value) const;
|
||||
|
||||
template <typename T>
|
||||
const T Read() const;
|
||||
|
||||
template <typename T>
|
||||
operator T() const;
|
||||
const T to() const;
|
||||
|
||||
template <typename T>
|
||||
friend void operator >> (const Node& node, T& value);
|
||||
@@ -127,24 +124,6 @@ namespace YAML
|
||||
node_seq m_seqData;
|
||||
node_map m_mapData;
|
||||
};
|
||||
|
||||
// comparisons with auto-conversion
|
||||
template <typename T>
|
||||
bool operator == (const T& value, const Node& node);
|
||||
|
||||
template <typename T>
|
||||
bool operator == (const Node& node, const T& value);
|
||||
|
||||
template <typename T>
|
||||
bool operator != (const T& value, const Node& node);
|
||||
|
||||
template <typename T>
|
||||
bool operator != (const Node& node, const T& value);
|
||||
|
||||
bool operator == (const char *value, const Node& node);
|
||||
bool operator == (const Node& node, const char *value);
|
||||
bool operator != (const char *value, const Node& node);
|
||||
bool operator != (const Node& node, const char *value);
|
||||
}
|
||||
|
||||
#include "yaml-cpp/nodeimpl.h"
|
||||
|
@@ -13,16 +13,11 @@ namespace YAML
|
||||
{
|
||||
// implementation of templated things
|
||||
template <typename T>
|
||||
inline const T Node::Read() const {
|
||||
inline const T Node::to() const {
|
||||
T value;
|
||||
*this >> value;
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Node::operator T() const {
|
||||
return Read<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator >> (const Node& node, T& value) {
|
||||
@@ -77,43 +72,6 @@ namespace YAML
|
||||
inline const Node& Node::operator [] (const char *key) const {
|
||||
return GetValue(std::string(key));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator == (const T& value, const Node& node) {
|
||||
return value == node.operator T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator == (const Node& node, const T& value) {
|
||||
return value == node.operator T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator != (const T& value, const Node& node) {
|
||||
return value != node.operator T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator != (const Node& node, const T& value) {
|
||||
return value != node.operator T();
|
||||
}
|
||||
|
||||
inline bool operator == (const char *value, const Node& node) {
|
||||
return std::string(value) == node;
|
||||
}
|
||||
|
||||
inline bool operator == (const Node& node, const char *value) {
|
||||
return std::string(value) == node;
|
||||
}
|
||||
|
||||
inline bool operator != (const char *value, const Node& node) {
|
||||
return std::string(value) != node;
|
||||
}
|
||||
|
||||
inline bool operator != (const Node& node, const char *value) {
|
||||
return std::string(value) != node;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@@ -132,14 +132,11 @@ namespace Test
|
||||
parser.GetNextDocument(doc);
|
||||
|
||||
std::string output;
|
||||
doc[0] >> output;
|
||||
if(output != "eggs")
|
||||
if(doc[0].to<std::string>() != "eggs")
|
||||
return false;
|
||||
doc[1] >> output;
|
||||
if(output != "bread")
|
||||
if(doc[1].to<std::string>() != "bread")
|
||||
return false;
|
||||
doc[2] >> output;
|
||||
if(output != "milk")
|
||||
if(doc[2].to<std::string>() != "milk")
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -626,7 +623,7 @@ namespace Test
|
||||
return false;
|
||||
if(!IsNull(doc["key"]))
|
||||
return false;
|
||||
if(doc["just a key"] != "value")
|
||||
if(doc["just a key"].to<std::string>() != "value")
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -647,13 +644,13 @@ namespace Test
|
||||
parser.GetNextDocument(doc);
|
||||
if(doc.size() != 4)
|
||||
return false;
|
||||
if(doc[0] != 15)
|
||||
if(doc[0].to<int>() != 15)
|
||||
return false;
|
||||
if(doc[1] != 0x10)
|
||||
if(doc[1].to<int>() != 0x10)
|
||||
return false;
|
||||
if(doc[2] != 030)
|
||||
if(doc[2].to<int>() != 030)
|
||||
return false;
|
||||
if(doc[3] != 0xffffffff)
|
||||
if(doc[3].to<unsigned>() != 0xffffffff)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -698,11 +695,11 @@ namespace Test
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
|
||||
if(doc["a"] != 4)
|
||||
if(doc["a"].to<int>() != 4)
|
||||
return false;
|
||||
if(doc["b"] != 2)
|
||||
if(doc["b"].to<int>() != 2)
|
||||
return false;
|
||||
if(doc["c"] != 3)
|
||||
if(doc["c"].to<int>() != 3)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user