From d506dae91451a7467abb2d14929591d345c88141 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Fri, 31 Jul 2009 05:07:21 +0000 Subject: [PATCH] Added IsNull function --- include/null.h | 4 ++++ src/null.cpp | 6 ++++++ yaml-reader/parsertests.cpp | 7 ++----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/null.h b/include/null.h index c7c43cc..7036f98 100644 --- a/include/null.h +++ b/include/null.h @@ -6,10 +6,14 @@ namespace YAML { + class Node; + struct _Null {}; inline bool operator == (const _Null&, const _Null&) { return true; } inline bool operator != (const _Null&, const _Null&) { return false; } + bool IsNull(const Node& node); + extern _Null Null; } diff --git a/src/null.cpp b/src/null.cpp index 853d49a..faa05fb 100644 --- a/src/null.cpp +++ b/src/null.cpp @@ -1,6 +1,12 @@ #include "null.h" +#include "node.h" namespace YAML { _Null Null; + + bool IsNull(const Node& node) + { + return node.Read(Null); + } } diff --git a/yaml-reader/parsertests.cpp b/yaml-reader/parsertests.cpp index 721ceb9..3b2e28d 100644 --- a/yaml-reader/parsertests.cpp +++ b/yaml-reader/parsertests.cpp @@ -261,8 +261,7 @@ namespace Test doc[0] >> output; if(output != "hello") return false; - doc[1] >> output; - if(output != "~") + if(!IsNull(doc[1])) return false; doc[2] >> output; if(output != "world") @@ -297,9 +296,7 @@ namespace Test YAML::Node doc; parser.GetNextDocument(doc); - std::string output; - doc["empty value"] >> output; - if(output != "~") + if(!IsNull(doc["empty value"])) return false; return true;