1 #include "graphbuilderadapter.h"
5 int GraphBuilderAdapter::ContainerFrame::sequenceMarker
;
7 void GraphBuilderAdapter::OnNull(const Mark
& mark
, anchor_t anchor
)
9 void *pParent
= GetCurrentParent();
10 void *pNode
= m_builder
.NewNull(mark
, pParent
);
11 RegisterAnchor(anchor
, pNode
);
13 DispositionNode(pNode
);
16 void GraphBuilderAdapter::OnAlias(const Mark
& mark
, anchor_t anchor
)
18 void *pReffedNode
= m_anchors
.Get(anchor
);
19 DispositionNode(m_builder
.AnchorReference(mark
, pReffedNode
));
22 void GraphBuilderAdapter::OnScalar(const Mark
& mark
, const std::string
& tag
, anchor_t anchor
, const std::string
& value
)
24 void *pParent
= GetCurrentParent();
25 void *pNode
= m_builder
.NewScalar(mark
, tag
, pParent
, value
);
26 RegisterAnchor(anchor
, pNode
);
28 DispositionNode(pNode
);
31 void GraphBuilderAdapter::OnSequenceStart(const Mark
& mark
, const std::string
& tag
, anchor_t anchor
)
33 void *pNode
= m_builder
.NewSequence(mark
, tag
, GetCurrentParent());
34 m_containers
.push(ContainerFrame(pNode
));
35 RegisterAnchor(anchor
, pNode
);
38 void GraphBuilderAdapter::OnSequenceEnd()
40 void *pSequence
= m_containers
.top().pContainer
;
43 DispositionNode(pSequence
);
46 void GraphBuilderAdapter::OnMapStart(const Mark
& mark
, const std::string
& tag
, anchor_t anchor
)
48 void *pNode
= m_builder
.NewMap(mark
, tag
, GetCurrentParent());
49 m_containers
.push(ContainerFrame(pNode
, m_pKeyNode
));
51 RegisterAnchor(anchor
, pNode
);
54 void GraphBuilderAdapter::OnMapEnd()
56 void *pMap
= m_containers
.top().pContainer
;
57 m_pKeyNode
= m_containers
.top().pPrevKeyNode
;
59 DispositionNode(pMap
);
62 void *GraphBuilderAdapter::GetCurrentParent() const
64 if (m_containers
.empty()) {
67 return m_containers
.top().pContainer
;
70 void GraphBuilderAdapter::RegisterAnchor(anchor_t anchor
, void *pNode
)
73 m_anchors
.Register(anchor
, pNode
);
77 void GraphBuilderAdapter::DispositionNode(void *pNode
)
79 if (m_containers
.empty()) {
84 void *pContainer
= m_containers
.top().pContainer
;
85 if (m_containers
.top().isMap()) {
87 m_builder
.AssignInMap(pContainer
, m_pKeyNode
, pNode
);
93 m_builder
.AppendToSequence(pContainer
, pNode
);