File: Types.cpp

package info (click to toggle)
eris 1.3.10-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,592 kB
  • ctags: 1,516
  • sloc: cpp: 9,850; sh: 8,288; perl: 287; ansic: 165; makefile: 162
file content (44 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifdef HAVE_CONFIG_H
	#include "config.h"
#endif

#include <Eris/Types.h>
#include <Atlas/Message/Element.h>

using namespace Atlas::Message;

namespace Eris
{

void mergeOrCopyElement(const Element& src, Element& dst)
{
    if (!src.isMap() || !dst.isMap()) {
        dst = src;
        return;
    }
    
    const MapType& srcMap(src.asMap());
    MapType& dstMap(dst.asMap());
    
    MapType::iterator dit = dstMap.begin();
    MapType::const_iterator sit = srcMap.begin();
    
    for (; sit != srcMap.end(); ++sit) {   
        // advance destination to us / past us
        while (dit->first < sit->first) ++dit;
        if (dit == dstMap.end()) break;
        
        if (dit->first == sit->first) {
            // exists in destination, merge
            mergeOrCopyElement(sit->second, dit->second);
        } else {
            // only in source, insert
            dstMap.insert(dit, *sit);
        }
    } // of source map iteration
    
    // copy over remanining attrs
    while (sit != srcMap.end()) dstMap.insert(dit, *sit++);
}

} // of namespace