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