Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
12364895
Commit
12364895
authored
Sep 10, 2011
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented value events emitter
parent
50120631
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
6 deletions
+98
-6
src/value/valueevents.cpp
+75
-5
src/value/valueevents.h
+23
-1
No files found.
src/value/valueevents.cpp
View file @
12364895
#include "valueevents.h"
#include "yaml-cpp/value.h"
#include "yaml-cpp/eventhandler.h"
#include "yaml-cpp/mark.h"
namespace
YAML
{
void
ValueEvents
::
AliasManager
::
RegisterReference
(
const
detail
::
node
&
node
)
{
m_anchorByIdentity
.
insert
(
std
::
make_pair
(
node
.
ref
(),
_CreateNewAnchor
()));
}
anchor_t
ValueEvents
::
AliasManager
::
LookupAnchor
(
const
detail
::
node
&
node
)
const
{
AnchorByIdentity
::
const_iterator
it
=
m_anchorByIdentity
.
find
(
node
.
ref
());
if
(
it
==
m_anchorByIdentity
.
end
())
return
0
;
return
it
->
second
;
}
ValueEvents
::
ValueEvents
(
const
Value
&
value
)
:
m_pMemory
(
value
.
m_pMemory
),
m_root
(
*
value
.
m_pNode
)
{
Visit
(
m_root
);
Setup
(
m_root
);
}
void
ValueEvents
::
Visit
(
const
detail
::
node
&
node
)
void
ValueEvents
::
Setup
(
const
detail
::
node
&
node
)
{
int
&
refCount
=
m_refCount
[
node
.
ref
()];
refCount
++
;
...
...
@@ -17,12 +32,67 @@ namespace YAML
if
(
node
.
type
()
==
ValueType
::
Sequence
)
{
for
(
detail
::
const_node_iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
Visit
(
**
it
);
Setup
(
**
it
);
}
else
if
(
node
.
type
()
==
ValueType
::
Map
)
{
for
(
detail
::
const_node_iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
{
Visit
(
*
it
->
first
);
Visit
(
*
it
->
second
);
Setup
(
*
it
->
first
);
Setup
(
*
it
->
second
);
}
}
}
void
ValueEvents
::
Emit
(
EventHandler
&
handler
)
{
AliasManager
am
;
handler
.
OnDocumentStart
(
Mark
());
Emit
(
m_root
,
handler
,
am
);
handler
.
OnDocumentEnd
();
}
void
ValueEvents
::
Emit
(
const
detail
::
node
&
node
,
EventHandler
&
handler
,
AliasManager
&
am
)
const
{
anchor_t
anchor
=
NullAnchor
;
if
(
IsAliased
(
node
))
{
anchor
=
am
.
LookupAnchor
(
node
);
if
(
anchor
)
{
handler
.
OnAlias
(
Mark
(),
anchor
);
return
;
}
am
.
RegisterReference
(
node
);
anchor
=
am
.
LookupAnchor
(
node
);
}
switch
(
node
.
type
())
{
case
ValueType
:
:
Undefined
:
break
;
case
ValueType
:
:
Null
:
handler
.
OnNull
(
Mark
(),
anchor
);
break
;
case
ValueType
:
:
Scalar
:
handler
.
OnScalar
(
Mark
(),
""
,
anchor
,
node
.
scalar
());
break
;
case
ValueType
:
:
Sequence
:
handler
.
OnSequenceStart
(
Mark
(),
""
,
anchor
);
for
(
detail
::
const_node_iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
Emit
(
**
it
,
handler
,
am
);
handler
.
OnSequenceEnd
();
break
;
case
ValueType
:
:
Map
:
handler
.
OnMapStart
(
Mark
(),
""
,
anchor
);
for
(
detail
::
const_node_iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
{
Emit
(
*
it
->
first
,
handler
,
am
);
Emit
(
*
it
->
second
,
handler
,
am
);
}
handler
.
OnMapEnd
();
break
;
}
}
bool
ValueEvents
::
IsAliased
(
const
detail
::
node
&
node
)
const
{
RefCount
::
const_iterator
it
=
m_refCount
.
find
(
node
.
ref
());
return
it
!=
m_refCount
.
end
()
&&
it
->
second
>
1
;
}
}
src/value/valueevents.h
View file @
12364895
...
...
@@ -13,14 +13,36 @@
namespace
YAML
{
class
Value
;
class
EventHandler
;
class
ValueEvents
{
public
:
ValueEvents
(
const
Value
&
value
);
void
Emit
(
EventHandler
&
handler
);
private
:
void
Visit
(
const
detail
::
node
&
node
);
class
AliasManager
{
public
:
AliasManager
()
:
m_curAnchor
(
0
)
{}
void
RegisterReference
(
const
detail
::
node
&
node
);
anchor_t
LookupAnchor
(
const
detail
::
node
&
node
)
const
;
private
:
anchor_t
_CreateNewAnchor
()
{
return
++
m_curAnchor
;
}
private
:
typedef
std
::
map
<
const
detail
::
node_ref
*
,
anchor_t
>
AnchorByIdentity
;
AnchorByIdentity
m_anchorByIdentity
;
anchor_t
m_curAnchor
;
};
void
Setup
(
const
detail
::
node
&
node
);
void
Emit
(
const
detail
::
node
&
node
,
EventHandler
&
handler
,
AliasManager
&
am
)
const
;
bool
IsAliased
(
const
detail
::
node
&
node
)
const
;
private
:
detail
::
shared_memory_holder
m_pMemory
;
...
...
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