mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Replaced a pointer-centered try/catch block with std::auto_ptr
This commit is contained in:
26
src/map.cpp
26
src/map.cpp
@@ -5,6 +5,7 @@
|
|||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@@ -66,10 +67,8 @@ namespace YAML
|
|||||||
if(token.type == TT_BLOCK_END)
|
if(token.type == TT_BLOCK_END)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
Node *pKey = new Node;
|
std::auto_ptr <Node> pKey(new Node), pValue(new Node);
|
||||||
Node *pValue = new Node;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// grab key
|
// grab key
|
||||||
pKey->Parse(pScanner, state);
|
pKey->Parse(pScanner, state);
|
||||||
|
|
||||||
@@ -79,12 +78,8 @@ namespace YAML
|
|||||||
pValue->Parse(pScanner, state);
|
pValue->Parse(pScanner, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data[pKey] = pValue;
|
// assign the map with the actual pointers
|
||||||
} catch(Exception&) {
|
m_data[pKey.release()] = pValue.release();
|
||||||
delete pKey;
|
|
||||||
delete pValue;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,10 +105,8 @@ namespace YAML
|
|||||||
|
|
||||||
pScanner->pop();
|
pScanner->pop();
|
||||||
|
|
||||||
Node *pKey = new Node;
|
std::auto_ptr <Node> pKey(new Node), pValue(new Node);
|
||||||
Node *pValue = new Node;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// grab key
|
// grab key
|
||||||
pKey->Parse(pScanner, state);
|
pKey->Parse(pScanner, state);
|
||||||
|
|
||||||
@@ -130,13 +123,8 @@ namespace YAML
|
|||||||
else if(nextToken.type != TT_FLOW_MAP_END)
|
else if(nextToken.type != TT_FLOW_MAP_END)
|
||||||
throw ParserException(nextToken.line, nextToken.column, ErrorMsg::END_OF_MAP_FLOW);
|
throw ParserException(nextToken.line, nextToken.column, ErrorMsg::END_OF_MAP_FLOW);
|
||||||
|
|
||||||
m_data[pKey] = pValue;
|
// assign the map with the actual pointers
|
||||||
} catch(Exception&) {
|
m_data[pKey.release()] = pValue.release();
|
||||||
// clean up and rethrow
|
|
||||||
delete pKey;
|
|
||||||
delete pValue;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user