From f8d81fff8c10c574c491633ca08b842073489d1f Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 20 Nov 2008 03:41:40 +0000 Subject: [PATCH] Replaced a pointer-centered try/catch block with std::auto_ptr --- src/map.cpp | 68 ++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index 89f5b70..4af27c3 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -5,6 +5,7 @@ #include "token.h" #include "exceptions.h" #include +#include namespace YAML { @@ -66,25 +67,19 @@ namespace YAML if(token.type == TT_BLOCK_END) break; - Node *pKey = new Node; - Node *pValue = new Node; + std::auto_ptr pKey(new Node), pValue(new Node); - try { - // grab key - pKey->Parse(pScanner, state); + // grab key + pKey->Parse(pScanner, state); - // now grab value (optional) - if(!pScanner->empty() && pScanner->peek().type == TT_VALUE) { - pScanner->pop(); - pValue->Parse(pScanner, state); - } - - m_data[pKey] = pValue; - } catch(Exception&) { - delete pKey; - delete pValue; - throw; + // now grab value (optional) + if(!pScanner->empty() && pScanner->peek().type == TT_VALUE) { + pScanner->pop(); + pValue->Parse(pScanner, state); } + + // assign the map with the actual pointers + m_data[pKey.release()] = pValue.release(); } } @@ -110,33 +105,26 @@ namespace YAML pScanner->pop(); - Node *pKey = new Node; - Node *pValue = new Node; + std::auto_ptr pKey(new Node), pValue(new Node); - try { - // grab key - pKey->Parse(pScanner, state); + // grab key + pKey->Parse(pScanner, state); - // now grab value (optional) - if(!pScanner->empty() && pScanner->peek().type == TT_VALUE) { - pScanner->pop(); - pValue->Parse(pScanner, state); - } - - // now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node) - Token& nextToken = pScanner->peek(); - if(nextToken.type == TT_FLOW_ENTRY) - pScanner->pop(); - else if(nextToken.type != TT_FLOW_MAP_END) - throw ParserException(nextToken.line, nextToken.column, ErrorMsg::END_OF_MAP_FLOW); - - m_data[pKey] = pValue; - } catch(Exception&) { - // clean up and rethrow - delete pKey; - delete pValue; - throw; + // now grab value (optional) + if(!pScanner->empty() && pScanner->peek().type == TT_VALUE) { + pScanner->pop(); + pValue->Parse(pScanner, state); } + + // now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node) + Token& nextToken = pScanner->peek(); + if(nextToken.type == TT_FLOW_ENTRY) + pScanner->pop(); + else if(nextToken.type != TT_FLOW_MAP_END) + throw ParserException(nextToken.line, nextToken.column, ErrorMsg::END_OF_MAP_FLOW); + + // assign the map with the actual pointers + m_data[pKey.release()] = pValue.release(); } }