graphbuilderadapter.cpp
Go to the documentation of this file.
00001 #include "graphbuilderadapter.h"
00002 
00003 namespace YAML_PM
00004 {
00005   int GraphBuilderAdapter::ContainerFrame::sequenceMarker;
00006   
00007   void GraphBuilderAdapter::OnNull(const Mark& mark, anchor_t anchor)
00008   {
00009     void *pParent = GetCurrentParent();
00010     void *pNode = m_builder.NewNull(mark, pParent);
00011     RegisterAnchor(anchor, pNode);
00012     
00013     DispositionNode(pNode);
00014   }
00015   
00016   void GraphBuilderAdapter::OnAlias(const Mark& mark, anchor_t anchor)
00017   {
00018     void *pReffedNode = m_anchors.Get(anchor);
00019     DispositionNode(m_builder.AnchorReference(mark, pReffedNode));
00020   }
00021   
00022   void GraphBuilderAdapter::OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value)
00023   {
00024     void *pParent = GetCurrentParent();
00025     void *pNode = m_builder.NewScalar(mark, tag, pParent, value);
00026     RegisterAnchor(anchor, pNode);
00027     
00028     DispositionNode(pNode);
00029   }
00030   
00031   void GraphBuilderAdapter::OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor)
00032   {
00033     void *pNode = m_builder.NewSequence(mark, tag, GetCurrentParent());
00034     m_containers.push(ContainerFrame(pNode));
00035     RegisterAnchor(anchor, pNode);
00036   }
00037   
00038   void GraphBuilderAdapter::OnSequenceEnd()
00039   {
00040     void *pSequence = m_containers.top().pContainer;
00041     m_containers.pop();
00042     
00043     DispositionNode(pSequence);
00044   }
00045   
00046   void GraphBuilderAdapter::OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor)
00047   {
00048     void *pNode = m_builder.NewMap(mark, tag, GetCurrentParent());
00049     m_containers.push(ContainerFrame(pNode, m_pKeyNode));
00050     m_pKeyNode = NULL;
00051     RegisterAnchor(anchor, pNode);
00052   }
00053   
00054   void GraphBuilderAdapter::OnMapEnd()
00055   {
00056     void *pMap = m_containers.top().pContainer;
00057     m_pKeyNode = m_containers.top().pPrevKeyNode;
00058     m_containers.pop();
00059     DispositionNode(pMap);
00060   }
00061   
00062   void *GraphBuilderAdapter::GetCurrentParent() const
00063   {
00064     if (m_containers.empty()) {
00065       return NULL;
00066     }
00067     return m_containers.top().pContainer;
00068   }
00069   
00070   void GraphBuilderAdapter::RegisterAnchor(anchor_t anchor, void *pNode)
00071   {
00072     if (anchor) {
00073       m_anchors.Register(anchor, pNode);
00074     }
00075   }
00076   
00077   void GraphBuilderAdapter::DispositionNode(void *pNode)
00078   {
00079     if (m_containers.empty()) {
00080       m_pRootNode = pNode;
00081       return;
00082     }
00083     
00084     void *pContainer = m_containers.top().pContainer;
00085     if (m_containers.top().isMap()) {
00086       if (m_pKeyNode) {
00087         m_builder.AssignInMap(pContainer, m_pKeyNode, pNode);
00088         m_pKeyNode = NULL;
00089       } else {
00090         m_pKeyNode = pNode;
00091       }
00092     } else {
00093       m_builder.AppendToSequence(pContainer, pNode);
00094     }
00095   }
00096 }


libpointmatcher
Author(s):
autogenerated on Mon Sep 14 2015 02:59:04