From ed570b9f7cecacc3e6a10c5b0df3d66a54ed659c Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Mon, 19 Oct 2009 22:40:46 +0000 Subject: [PATCH] Added default constructor to Parser, and cleaned it up a bit --- include/parser.h | 16 +++++++--------- src/parser.cpp | 14 ++++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/parser.h b/include/parser.h index f3a487c..9f24916 100644 --- a/include/parser.h +++ b/include/parser.h @@ -4,21 +4,24 @@ #define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#include "node.h" +#include "parserstate.h" +#include "noncopyable.h" #include #include #include #include -#include "node.h" -#include "parserstate.h" +#include namespace YAML { class Scanner; struct Token; - class Parser + class Parser: private noncopyable { public: + Parser(); Parser(std::istream& in); ~Parser(); @@ -35,12 +38,7 @@ namespace YAML void HandleTagDirective(Token *pToken); private: - // can't copy this - Parser(const Parser&) {} - Parser& operator = (const Parser&) { return *this; } - - private: - Scanner *m_pScanner; + std::auto_ptr m_pScanner; ParserState m_state; }; } diff --git a/src/parser.cpp b/src/parser.cpp index 9cbfe32..283bb94 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -8,25 +8,27 @@ namespace YAML { - Parser::Parser(std::istream& in): m_pScanner(0) + Parser::Parser() + { + } + + Parser::Parser(std::istream& in) { Load(in); } Parser::~Parser() { - delete m_pScanner; } Parser::operator bool() const { - return !m_pScanner->empty(); + return m_pScanner.get() && !m_pScanner->empty(); } void Parser::Load(std::istream& in) { - delete m_pScanner; - m_pScanner = new Scanner(in); + m_pScanner.reset(new Scanner(in)); m_state.Reset(); } @@ -50,7 +52,7 @@ namespace YAML m_pScanner->pop(); // now parse our root node - document.Parse(m_pScanner, m_state); + document.Parse(m_pScanner.get(), m_state); // and finally eat any doc ends we see while(!m_pScanner->empty() && m_pScanner->peek().type == Token::DOC_END)