11 |
12 | #include "../anchor.h"
13 |
14 | namespace YAML {
15 | /**
16 | * An object that stores and retrieves values correlating to {@link anchor_t}
17 | * values.
18 | *
19 | * Efficient implementation that can make assumptions about how
20 | * {@code anchor_t} values are assigned by the {@link Parser} class.
21 | */
22 | template
23 | class AnchorDict {
24 | public:
25 | AnchorDict() : m_data{} {}
26 | void Register(anchor_t anchor, T value) {
27 | if (anchor > m_data.size()) {
28 | m_data.resize(anchor);
29 | }
30 | m_data[anchor - 1] = value;
31 | }
32 |
33 | T Get(anchor_t anchor) const { return m_data[anchor - 1]; }
34 |
35 | private:
36 | std::vector m_data;
37 | };
38 | } // namespace YAML
39 |
40 | #endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
41 |
--------------------------------------------------------------------------------
/include/yaml-cpp/contrib/graphbuilder.h:
--------------------------------------------------------------------------------
1 | #ifndef GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 | #define GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3 |
4 | #if defined(_MSC_VER) || \
5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7 | #pragma once
8 | #endif
9 |
10 | #include "yaml-cpp/mark.h"
11 | #include
12 |
13 | namespace YAML {
14 | class Parser;
15 |
16 | // GraphBuilderInterface
17 | // . Abstraction of node creation
18 | // . pParentNode is always nullptr or the return value of one of the NewXXX()
19 | // functions.
20 | class GraphBuilderInterface {
21 | public:
22 | virtual ~GraphBuilderInterface() = 0;
23 |
24 | // Create and return a new node with a null value.
25 | virtual void *NewNull(const Mark &mark, void *pParentNode) = 0;
26 |
27 | // Create and return a new node with the given tag and value.
28 | virtual void *NewScalar(const Mark &mark, const std::string &tag,
29 | void *pParentNode, const std::string &value) = 0;
30 |
31 | // Create and return a new sequence node
32 | virtual void *NewSequence(const Mark &mark, const std::string &tag,
33 | void *pParentNode) = 0;
34 |
35 | // Add pNode to pSequence. pNode was created with one of the NewXxx()
36 | // functions and pSequence with NewSequence().
37 | virtual void AppendToSequence(void *pSequence, void *pNode) = 0;
38 |
39 | // Note that no moew entries will be added to pSequence
40 | virtual void SequenceComplete(void *pSequence) { (void)pSequence; }
41 |
42 | // Create and return a new map node
43 | virtual void *NewMap(const Mark &mark, const std::string &tag,
44 | void *pParentNode) = 0;
45 |
46 | // Add the pKeyNode => pValueNode mapping to pMap. pKeyNode and pValueNode
47 | // were created with one of the NewXxx() methods and pMap with NewMap().
48 | virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) = 0;
49 |
50 | // Note that no more assignments will be made in pMap
51 | virtual void MapComplete(void *pMap) { (void)pMap; }
52 |
53 | // Return the node that should be used in place of an alias referencing
54 | // pNode (pNode by default)
55 | virtual void *AnchorReference(const Mark &mark, void *pNode) {
56 | (void)mark;
57 | return pNode;
58 | }
59 | };
60 |
61 | // Typesafe wrapper for GraphBuilderInterface. Assumes that Impl defines
62 | // Node, Sequence, and Map types. Sequence and Map must derive from Node
63 | // (unless Node is defined as void). Impl must also implement function with
64 | // all of the same names as the virtual functions in GraphBuilderInterface
65 | // -- including the ones with default implementations -- but with the
66 | // prototypes changed to accept an explicit Node*, Sequence*, or Map* where
67 | // appropriate.
68 | template
69 | class GraphBuilder : public GraphBuilderInterface {
70 | public:
71 | typedef typename Impl::Node Node;
72 | typedef typename Impl::Sequence Sequence;
73 | typedef typename Impl::Map Map;
74 |
75 | GraphBuilder(Impl &impl) : m_impl(impl) {
76 | Map *pMap = nullptr;
77 | Sequence *pSeq = nullptr;
78 | Node *pNode = nullptr;
79 |
80 | // Type consistency checks
81 | pNode = pMap;
82 | pNode = pSeq;
83 | }
84 |
85 | GraphBuilderInterface &AsBuilderInterface() { return *this; }
86 |
87 | virtual void *NewNull(const Mark &mark, void *pParentNode) {
88 | return CheckType(m_impl.NewNull(mark, AsNode(pParentNode)));
89 | }
90 |
91 | virtual void *NewScalar(const Mark &mark, const std::string &tag,
92 | void *pParentNode, const std::string &value) {
93 | return CheckType(
94 | m_impl.NewScalar(mark, tag, AsNode(pParentNode), value));
95 | }
96 |
97 | virtual void *NewSequence(const Mark &mark, const std::string &tag,
98 | void *pParentNode) {
99 | return CheckType(
100 | m_impl.NewSequence(mark, tag, AsNode(pParentNode)));
101 | }
102 | virtual void AppendToSequence(void *pSequence, void *pNode) {
103 | m_impl.AppendToSequence(AsSequence(pSequence), AsNode(pNode));
104 | }
105 | virtual void SequenceComplete(void *pSequence) {
106 | m_impl.SequenceComplete(AsSequence(pSequence));
107 | }
108 |
109 | virtual void *NewMap(const Mark &mark, const std::string &tag,
110 | void *pParentNode) {
111 | return CheckType