Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
f8d81fff
"vscode:/vscode.git/clone" did not exist on "f451e1e451f1caebdd323fbf2bf1efb677fd3d44"
Commit
f8d81fff
authored
Nov 20, 2008
by
Jesse Beder
Browse files
Replaced a pointer-centered try/catch block with std::auto_ptr
parent
043bbddc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
42 deletions
+30
-42
src/map.cpp
src/map.cpp
+30
-42
No files found.
src/map.cpp
View file @
f8d81fff
...
@@ -5,6 +5,7 @@
...
@@ -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,25 +67,19 @@ namespace YAML
...
@@ -66,25 +67,19 @@ 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
);
// now grab value (optional)
// now grab value (optional)
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
TT_VALUE
)
{
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
TT_VALUE
)
{
pScanner
->
pop
();
pScanner
->
pop
();
pValue
->
Parse
(
pScanner
,
state
);
pValue
->
Parse
(
pScanner
,
state
);
}
m_data
[
pKey
]
=
pValue
;
}
catch
(
Exception
&
)
{
delete
pKey
;
delete
pValue
;
throw
;
}
}
// assign the map with the actual pointers
m_data
[
pKey
.
release
()]
=
pValue
.
release
();
}
}
}
}
...
@@ -110,33 +105,26 @@ namespace YAML
...
@@ -110,33 +105,26 @@ namespace YAML
pScanner
->
pop
();
pScanner
->
pop
();
Node
*
pKey
=
new
Node
;
std
::
auto_ptr
<
Node
>
pKey
(
new
Node
),
pValue
(
new
Node
);
Node
*
pValue
=
new
Node
;
// grab key
try
{
pKey
->
Parse
(
pScanner
,
state
);
// grab key
pKey
->
Parse
(
pScanner
,
state
);
// now grab value (optional)
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
TT_VALUE
)
{
// now grab value (optional)
pScanner
->
pop
();
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
TT_VALUE
)
{
pValue
->
Parse
(
pScanner
,
state
);
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 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
();
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment