~ubuntu-branches/ubuntu/breezy/atlas-cpp/breezy

« back to all changes in this revision

Viewing changes to Atlas/Message/MEncoder.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2005-10-02 11:41:44 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051002114144-8qmn4d1cdn9g27ta
Tags: 0.5.98-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file may be redistributed and modified only under the terms of
 
2
// the GNU Lesser General Public License (See COPYING for details).
 
3
// Copyright (C) 2000 Stefanus Du Toit
 
4
 
 
5
#include <Atlas/Message/MEncoder.h>
 
6
 
 
7
#include <Atlas/Message/Element.h>
 
8
 
 
9
namespace Atlas { namespace Message {
 
10
 
 
11
Encoder::Encoder(Atlas::Bridge & b)
 
12
    : EncoderBase(b)
 
13
{
 
14
}
 
15
 
 
16
Encoder::~Encoder()
 
17
{
 
18
}
 
19
 
 
20
void Encoder::listElementItem(const Element& obj)
 
21
{
 
22
    switch (obj.getType()) {
 
23
        case Element::TYPE_INT: m_b.listIntItem(obj.asInt()); break;
 
24
        case Element::TYPE_FLOAT: m_b.listFloatItem(obj.asFloat()); break;
 
25
        case Element::TYPE_STRING: m_b.listStringItem(obj.asString()); break;
 
26
        case Element::TYPE_MAP: {
 
27
            m_b.listMapItem();
 
28
            MapType::const_iterator I;
 
29
            for (I = obj.asMap().begin(); I != obj.asMap().end(); I++) {
 
30
                mapElementItem((*I).first, (*I).second);
 
31
            }
 
32
            m_b.mapEnd();
 
33
            }
 
34
            break;
 
35
        case Element::TYPE_LIST: {
 
36
            m_b.listListItem();
 
37
            ListType::const_iterator I;
 
38
            for (I = obj.asList().begin(); I != obj.asList().end(); I++) {
 
39
                listElementItem(*I);
 
40
            }
 
41
            m_b.listEnd();
 
42
            }
 
43
            break;
 
44
        default: break;
 
45
    }
 
46
}
 
47
 
 
48
void Encoder::listElementMapItem(const MapType& obj)
 
49
{
 
50
    m_b.listMapItem();
 
51
    MapType::const_iterator I;
 
52
    for (I = obj.begin(); I != obj.end(); I++) {
 
53
        mapElementItem(I->first, I->second);
 
54
    }
 
55
    m_b.mapEnd();
 
56
}
 
57
 
 
58
void Encoder::listElementListItem(const ListType& obj)
 
59
{
 
60
    m_b.listListItem();
 
61
    ListType::const_iterator I;
 
62
    for (I = obj.begin(); I != obj.end(); I++) {
 
63
        listElementItem(*I);
 
64
    }
 
65
    m_b.listEnd();    
 
66
}
 
67
 
 
68
void Encoder::mapElementItem(const std::string& name, const Element& obj)
 
69
{
 
70
    switch (obj.getType()) {
 
71
        case Element::TYPE_INT: m_b.mapIntItem(name, obj.asInt()); break;
 
72
        case Element::TYPE_FLOAT: m_b.mapFloatItem(name, obj.asFloat()); break;
 
73
        case Element::TYPE_STRING: m_b.mapStringItem(name, obj.asString()); break;
 
74
        case Element::TYPE_MAP: {
 
75
            m_b.mapMapItem(name);
 
76
            MapType::const_iterator I;
 
77
            for (I = obj.asMap().begin(); I != obj.asMap().end(); I++) {
 
78
                mapElementItem((*I).first, (*I).second);
 
79
            }
 
80
            m_b.mapEnd();
 
81
            }
 
82
            break;
 
83
        case Element::TYPE_LIST: {
 
84
            m_b.mapListItem(name);
 
85
            ListType::const_iterator I;
 
86
            for (I = obj.asList().begin(); I != obj.asList().end(); I++) {
 
87
                listElementItem(*I);
 
88
            }
 
89
            m_b.listEnd();
 
90
            }
 
91
            break;
 
92
        default:
 
93
            break;
 
94
    }                          
 
95
}
 
96
 
 
97
void Encoder::mapElementMapItem(const std::string& name, const MapType& obj)
 
98
{
 
99
    m_b.mapMapItem(name);
 
100
    MapType::const_iterator I;
 
101
    for (I = obj.begin(); I != obj.end(); I++) {
 
102
        mapElementItem((*I).first, (*I).second);
 
103
    }
 
104
    m_b.mapEnd();
 
105
}
 
106
 
 
107
void Encoder::mapElementListItem(const std::string& name, const ListType& obj)
 
108
{
 
109
    m_b.mapListItem(name);
 
110
    ListType::const_iterator I;
 
111
    for (I = obj.begin(); I != obj.end(); I++) {
 
112
        listElementItem(*I);
 
113
    }
 
114
    m_b.listEnd();
 
115
}
 
116
 
 
117
void Encoder::streamMessageElement(const MapType& obj)
 
118
{
 
119
    m_b.streamMessage();
 
120
    MapType::const_iterator I;
 
121
    for (I = obj.begin(); I != obj.end(); I++) {
 
122
        mapElementItem((*I).first, (*I).second);
 
123
    }
 
124
    m_b.mapEnd();
 
125
}
 
126
 
 
127
} } // namespace Atlas::Message