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
ed488e51
Commit
ed488e51
authored
Jul 04, 2008
by
Jesse Beder
Browse files
Removed the document class (since it's really just a root node, and that's it).
parent
2be40919
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
27 additions
and
103 deletions
+27
-103
document.cpp
document.cpp
+0
-63
document.h
document.h
+0
-26
main.cpp
main.cpp
+2
-2
node.h
node.h
+1
-0
parser.cpp
parser.cpp
+22
-2
parser.h
parser.h
+2
-2
yaml-reader.vcproj
yaml-reader.vcproj
+0
-8
No files found.
document.cpp
deleted
100644 → 0
View file @
2be40919
#include "document.h"
#include "node.h"
#include "token.h"
#include "scanner.h"
namespace
YAML
{
Document
::
Document
()
:
m_pRoot
(
0
)
{
}
Document
::~
Document
()
{
Clear
();
}
void
Document
::
Clear
()
{
delete
m_pRoot
;
m_pRoot
=
0
;
}
void
Document
::
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
)
{
Clear
();
// we better have some tokens in the queue
if
(
!
pScanner
->
PeekNextToken
())
return
;
// first eat doc start (optional)
if
(
pScanner
->
PeekNextToken
()
->
type
==
TT_DOC_START
)
pScanner
->
EatNextToken
();
// now create our root node and parse it
m_pRoot
=
new
Node
;
m_pRoot
->
Parse
(
pScanner
,
state
);
// and finally eat any doc ends we see
while
(
pScanner
->
PeekNextToken
()
&&
pScanner
->
PeekNextToken
()
->
type
==
TT_DOC_END
)
pScanner
->
EatNextToken
();
}
const
Node
&
Document
::
GetRoot
()
const
{
if
(
!
m_pRoot
)
throw
;
return
*
m_pRoot
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Document
&
doc
)
{
out
<<
"---
\n
"
;
if
(
!
doc
.
m_pRoot
)
{
out
<<
"{empty node}
\n
"
;
return
out
;
}
doc
.
m_pRoot
->
Write
(
out
,
0
);
return
out
;
}
}
document.h
deleted
100644 → 0
View file @
2be40919
#pragma once
#include <ios>
#include "parserstate.h"
namespace
YAML
{
class
Node
;
class
Scanner
;
class
Document
{
public:
Document
();
~
Document
();
void
Clear
();
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
const
Node
&
GetRoot
()
const
;
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Document
&
doc
);
private:
Node
*
m_pRoot
;
};
}
main.cpp
View file @
ed488e51
...
@@ -72,11 +72,11 @@ int main()
...
@@ -72,11 +72,11 @@ int main()
if
(
!
parser
)
if
(
!
parser
)
return
0
;
return
0
;
YAML
::
Document
doc
;
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
parser
.
GetNextDocument
(
doc
);
Level
level
;
Level
level
;
doc
.
GetRoot
()
>>
level
;
doc
>>
level
;
std
::
cout
<<
level
;
std
::
cout
<<
level
;
}
catch
(
YAML
::
Exception
&
)
{
}
catch
(
YAML
::
Exception
&
)
{
std
::
cout
<<
"Error parsing the yaml!
\n
"
;
std
::
cout
<<
"Error parsing the yaml!
\n
"
;
...
...
node.h
View file @
ed488e51
...
@@ -48,6 +48,7 @@ namespace YAML
...
@@ -48,6 +48,7 @@ namespace YAML
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
Write
(
std
::
ostream
&
out
,
int
indent
);
void
Write
(
std
::
ostream
&
out
,
int
indent
);
// accessors
Iterator
begin
()
const
;
Iterator
begin
()
const
;
Iterator
end
()
const
;
Iterator
end
()
const
;
unsigned
size
()
const
;
unsigned
size
()
const
;
...
...
parser.cpp
View file @
ed488e51
...
@@ -22,15 +22,35 @@ namespace YAML
...
@@ -22,15 +22,35 @@ namespace YAML
return
m_pScanner
->
PeekNextToken
()
!=
0
;
return
m_pScanner
->
PeekNextToken
()
!=
0
;
}
}
void
Parser
::
GetNextDocument
(
Document
&
document
)
// GetNextDocument
// . Reads the next document in the queue (of tokens).
// . Throws (ScannerException|ParserException)s on errors.
void
Parser
::
GetNextDocument
(
Node
&
document
)
{
{
// clear node
document
.
Clear
();
// first read directives
// first read directives
ParseDirectives
();
ParseDirectives
();
// then parse the document
// we better have some tokens in the queue
if
(
!
m_pScanner
->
PeekNextToken
())
return
;
// first eat doc start (optional)
if
(
m_pScanner
->
PeekNextToken
()
->
type
==
TT_DOC_START
)
m_pScanner
->
EatNextToken
();
// now parse our root node
document
.
Parse
(
m_pScanner
,
m_state
);
document
.
Parse
(
m_pScanner
,
m_state
);
// and finally eat any doc ends we see
while
(
m_pScanner
->
PeekNextToken
()
&&
m_pScanner
->
PeekNextToken
()
->
type
==
TT_DOC_END
)
m_pScanner
->
EatNextToken
();
}
}
// ParseDirectives
// . Reads any directives that are next in the queue.
void
Parser
::
ParseDirectives
()
void
Parser
::
ParseDirectives
()
{
{
bool
readDirective
=
false
;
bool
readDirective
=
false
;
...
...
parser.h
View file @
ed488e51
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <map>
#include <map>
#include "
document
.h"
#include "
node
.h"
#include "parserstate.h"
#include "parserstate.h"
namespace
YAML
namespace
YAML
...
@@ -20,7 +20,7 @@ namespace YAML
...
@@ -20,7 +20,7 @@ namespace YAML
operator
bool
()
const
;
operator
bool
()
const
;
void
GetNextDocument
(
Document
&
document
);
void
GetNextDocument
(
Node
&
document
);
void
PrintTokens
(
std
::
ostream
&
out
);
void
PrintTokens
(
std
::
ostream
&
out
);
private:
private:
...
...
yaml-reader.vcproj
View file @
ed488e51
...
@@ -216,10 +216,6 @@
...
@@ -216,10 +216,6 @@
RelativePath=
".\content.cpp"
RelativePath=
".\content.cpp"
>
>
</File>
</File>
<File
RelativePath=
".\document.cpp"
>
</File>
<File
<File
RelativePath=
".\iterator.cpp"
RelativePath=
".\iterator.cpp"
>
>
...
@@ -298,10 +294,6 @@
...
@@ -298,10 +294,6 @@
RelativePath=
".\content.h"
RelativePath=
".\content.h"
>
>
</File>
</File>
<File
RelativePath=
".\document.h"
>
</File>
<File
<File
RelativePath=
".\map.h"
RelativePath=
".\map.h"
>
>
...
...
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