Added IsNull function

This commit is contained in:
Jesse Beder
2009-07-31 05:07:21 +00:00
parent 7a89920441
commit d506dae914
3 changed files with 12 additions and 5 deletions

View File

@@ -6,10 +6,14 @@
namespace YAML namespace YAML
{ {
class Node;
struct _Null {}; struct _Null {};
inline bool operator == (const _Null&, const _Null&) { return true; } inline bool operator == (const _Null&, const _Null&) { return true; }
inline bool operator != (const _Null&, const _Null&) { return false; } inline bool operator != (const _Null&, const _Null&) { return false; }
bool IsNull(const Node& node);
extern _Null Null; extern _Null Null;
} }

View File

@@ -1,6 +1,12 @@
#include "null.h" #include "null.h"
#include "node.h"
namespace YAML namespace YAML
{ {
_Null Null; _Null Null;
bool IsNull(const Node& node)
{
return node.Read(Null);
}
} }

View File

@@ -261,8 +261,7 @@ namespace Test
doc[0] >> output; doc[0] >> output;
if(output != "hello") if(output != "hello")
return false; return false;
doc[1] >> output; if(!IsNull(doc[1]))
if(output != "~")
return false; return false;
doc[2] >> output; doc[2] >> output;
if(output != "world") if(output != "world")
@@ -297,9 +296,7 @@ namespace Test
YAML::Node doc; YAML::Node doc;
parser.GetNextDocument(doc); parser.GetNextDocument(doc);
std::string output; if(!IsNull(doc["empty value"]))
doc["empty value"] >> output;
if(output != "~")
return false; return false;
return true; return true;