graphbuilderadapter.h
Go to the documentation of this file.
00001 #ifndef GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00002 #define GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00003 
00004 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
00005 #pragma once
00006 #endif
00007 
00008 #include <cstdlib>
00009 #include <map>
00010 #include <stack>
00011 #include "yaml-cpp-pm/eventhandler.h"
00012 #include "yaml-cpp-pm/contrib/anchordict.h"
00013 #include "yaml-cpp-pm/contrib/graphbuilder.h"
00014 
00015 namespace YAML_PM
00016 {
00017   class GraphBuilderAdapter : public EventHandler
00018   {
00019   public:
00020     GraphBuilderAdapter(GraphBuilderInterface& builder)
00021     : m_builder(builder), m_pRootNode(NULL), m_pKeyNode(NULL)
00022     {
00023     }
00024     
00025     virtual void OnDocumentStart(const Mark& mark) {(void)mark;}
00026     virtual void OnDocumentEnd() {}
00027     
00028     virtual void OnNull(const Mark& mark, anchor_t anchor);
00029     virtual void OnAlias(const Mark& mark, anchor_t anchor);
00030     virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value);
00031     
00032     virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor);
00033     virtual void OnSequenceEnd();
00034     
00035     virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor);
00036     virtual void OnMapEnd();
00037     
00038     void *RootNode() const {return m_pRootNode;}
00039   
00040   private:
00041     struct ContainerFrame
00042     {
00043       ContainerFrame(void *pSequence)
00044       : pContainer(pSequence), pPrevKeyNode(&sequenceMarker)
00045       {}
00046       ContainerFrame(void *pMap, void* pPrevKeyNode)
00047       : pContainer(pMap), pPrevKeyNode(pPrevKeyNode)
00048       {}
00049       
00050       void *pContainer;
00051       void *pPrevKeyNode;
00052       
00053       bool isMap() const {return pPrevKeyNode != &sequenceMarker;}
00054     
00055     private:
00056       static int sequenceMarker;
00057     };
00058     typedef std::stack<ContainerFrame> ContainerStack;
00059     typedef AnchorDict<void*> AnchorMap;
00060     
00061     GraphBuilderInterface& m_builder;
00062     ContainerStack m_containers;
00063     AnchorMap m_anchors;
00064     void *m_pRootNode;
00065     void *m_pKeyNode;
00066     
00067     void *GetCurrentParent() const;
00068     void RegisterAnchor(anchor_t anchor, void *pNode);
00069     void DispositionNode(void *pNode);
00070   };
00071 }
00072 
00073 #endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:39