@@ -112,18 +112,48 @@ class node : private boost::noncopyable {
112112 value.add_dependency (*this );
113113 }
114114
115+ template <typename Key>
116+ inline node* GetValueFromMergeKey (const Key& key, node* currentValue,
117+ shared_memory_holder pMemory) const {
118+ node* mergeValue =
119+ static_cast <const node_ref&>(*m_pRef).get (to_value (" <<" ), pMemory);
120+ if (mergeValue) {
121+ if (mergeValue->type () == NodeType::Map) {
122+ return &mergeValue->get (key, pMemory);
123+ } else if (mergeValue->type () == NodeType::Sequence) {
124+ for (const_node_iterator it = mergeValue->begin ();
125+ it != mergeValue->end (); ++it) {
126+ if (it->pNode && it->pNode ->type () == NodeType::Map) {
127+ node* value = it->pNode ->get (key, pMemory);
128+ if (value && value->type () != NodeType::Undefined) {
129+ return value;
130+ }
131+ }
132+ }
133+ }
134+ }
135+ return currentValue;
136+ }
137+
115138 // indexing
116139 template <typename Key>
117140 node* get (const Key& key, shared_memory_holder pMemory) const {
118141 // NOTE: this returns a non-const node so that the top-level Node can wrap
119142 // it, and returns a pointer so that it can be NULL (if there is no such
120143 // key).
121- return static_cast <const node_ref&>(*m_pRef).get (key, pMemory);
144+ node* value = static_cast <const node_ref&>(*m_pRef).get (key, pMemory);
145+ if (!value || value->type () == NodeType::Undefined) {
146+ return GetValueFromMergeKey (key, value, pMemory);
147+ }
148+ return value;
122149 }
123150 template <typename Key>
124151 node& get (const Key& key, shared_memory_holder pMemory) {
125152 node& value = m_pRef->get (key, pMemory);
126153 value.add_dependency (*this );
154+ if (value.type () == NodeType::Undefined) {
155+ return *GetValueFromMergeKey (key, &value, pMemory);
156+ }
127157 return value;
128158 }
129159 template <typename Key>
0 commit comments