File: MEncoder.cpp

package info (click to toggle)
atlas-cpp 0.5.98-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,652 kB
  • ctags: 2,284
  • sloc: sh: 8,305; cpp: 6,372; python: 1,471; makefile: 216
file content (127 lines) | stat: -rw-r--r-- 3,563 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// This file may be redistributed and modified only under the terms of
// the GNU Lesser General Public License (See COPYING for details).
// Copyright (C) 2000 Stefanus Du Toit

#include <Atlas/Message/MEncoder.h>

#include <Atlas/Message/Element.h>

namespace Atlas { namespace Message {

Encoder::Encoder(Atlas::Bridge & b)
    : EncoderBase(b)
{
}

Encoder::~Encoder()
{
}

void Encoder::listElementItem(const Element& obj)
{
    switch (obj.getType()) {
        case Element::TYPE_INT: m_b.listIntItem(obj.asInt()); break;
        case Element::TYPE_FLOAT: m_b.listFloatItem(obj.asFloat()); break;
        case Element::TYPE_STRING: m_b.listStringItem(obj.asString()); break;
        case Element::TYPE_MAP: {
            m_b.listMapItem();
            MapType::const_iterator I;
            for (I = obj.asMap().begin(); I != obj.asMap().end(); I++) {
                mapElementItem((*I).first, (*I).second);
            }
            m_b.mapEnd();
            }
            break;
        case Element::TYPE_LIST: {
            m_b.listListItem();
            ListType::const_iterator I;
            for (I = obj.asList().begin(); I != obj.asList().end(); I++) {
                listElementItem(*I);
            }
            m_b.listEnd();
            }
            break;
        default: break;
    }
}

void Encoder::listElementMapItem(const MapType& obj)
{
    m_b.listMapItem();
    MapType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        mapElementItem(I->first, I->second);
    }
    m_b.mapEnd();
}

void Encoder::listElementListItem(const ListType& obj)
{
    m_b.listListItem();
    ListType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        listElementItem(*I);
    }
    m_b.listEnd();    
}

void Encoder::mapElementItem(const std::string& name, const Element& obj)
{
    switch (obj.getType()) {
        case Element::TYPE_INT: m_b.mapIntItem(name, obj.asInt()); break;
        case Element::TYPE_FLOAT: m_b.mapFloatItem(name, obj.asFloat()); break;
        case Element::TYPE_STRING: m_b.mapStringItem(name, obj.asString()); break;
        case Element::TYPE_MAP: {
            m_b.mapMapItem(name);
            MapType::const_iterator I;
            for (I = obj.asMap().begin(); I != obj.asMap().end(); I++) {
                mapElementItem((*I).first, (*I).second);
            }
            m_b.mapEnd();
            }
            break;
        case Element::TYPE_LIST: {
            m_b.mapListItem(name);
            ListType::const_iterator I;
            for (I = obj.asList().begin(); I != obj.asList().end(); I++) {
                listElementItem(*I);
            }
            m_b.listEnd();
            }
            break;
        default:
            break;
    }                          
}

void Encoder::mapElementMapItem(const std::string& name, const MapType& obj)
{
    m_b.mapMapItem(name);
    MapType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        mapElementItem((*I).first, (*I).second);
    }
    m_b.mapEnd();
}

void Encoder::mapElementListItem(const std::string& name, const ListType& obj)
{
    m_b.mapListItem(name);
    ListType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        listElementItem(*I);
    }
    m_b.listEnd();
}

void Encoder::streamMessageElement(const MapType& obj)
{
    m_b.streamMessage();
    MapType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        mapElementItem((*I).first, (*I).second);
    }
    m_b.mapEnd();
}

} } // namespace Atlas::Message