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

« back to all changes in this revision

Viewing changes to Atlas/Message/DecoderBase.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/DecoderBase.h>
 
6
 
 
7
#include <Atlas/Message/Element.h>
 
8
 
 
9
#include <Atlas/Debug.h>
 
10
 
 
11
#include <iostream>
 
12
 
 
13
#include <cassert>
 
14
 
 
15
static const bool debug_flag = false;
 
16
 
 
17
namespace Atlas { namespace Message {
 
18
 
 
19
DecoderBase::DecoderBase()
 
20
{
 
21
}
 
22
 
 
23
DecoderBase::~DecoderBase()
 
24
{
 
25
}
 
26
 
 
27
void DecoderBase::streamBegin()
 
28
{
 
29
    ATLAS_DEBUG(std::cout << "DecoderBase::streamBegin" << std::endl)
 
30
    m_state.push(STATE_STREAM);
 
31
}
 
32
 
 
33
void DecoderBase::streamMessage()
 
34
{
 
35
    ATLAS_DEBUG(std::cout << "DecoderBase::streamMessage" << std::endl)
 
36
    MapType m;
 
37
    m_maps.push(m);
 
38
    m_state.push(STATE_MAP);
 
39
}
 
40
 
 
41
void DecoderBase::streamEnd()
 
42
{
 
43
    ATLAS_DEBUG(std::cout << "DecoderBase::streamEnd" << std::endl)
 
44
    assert(!m_state.empty());
 
45
    m_state.pop();
 
46
}
 
47
 
 
48
void DecoderBase::mapMapItem(const std::string& name)
 
49
{
 
50
    ATLAS_DEBUG(std::cout << "DecoderBase::mapMapItem Map" << std::endl)
 
51
    MapType m;
 
52
    m_names.push(name);
 
53
    m_maps.push(m);
 
54
    m_state.push(STATE_MAP);
 
55
}
 
56
 
 
57
void DecoderBase::mapListItem(const std::string& name)
 
58
{
 
59
    ATLAS_DEBUG(std::cout << "DecoderBase::mapListItem List" << std::endl)
 
60
    ListType l;
 
61
    m_names.push(name);
 
62
    m_lists.push(l);
 
63
    m_state.push(STATE_LIST);
 
64
}
 
65
 
 
66
void DecoderBase::mapIntItem(const std::string& name, long i)
 
67
{
 
68
    ATLAS_DEBUG(std::cout << "DecoderBase::mapIntItem" << std::endl)
 
69
    assert(!m_maps.empty());        
 
70
    m_maps.top()[name] = i;
 
71
}
 
72
 
 
73
void DecoderBase::mapFloatItem(const std::string& name, double d)
 
74
{
 
75
    ATLAS_DEBUG(std::cout << "DecoderBase::mapFloatItem" << std::endl)
 
76
    assert(!m_maps.empty());       
 
77
    m_maps.top()[name] = d;
 
78
}
 
79
 
 
80
void DecoderBase::mapStringItem(const std::string& name, const std::string& s)
 
81
{
 
82
    ATLAS_DEBUG(std::cout << "DecoderBase::mapStringItem" << std::endl)
 
83
    assert(!m_maps.empty());
 
84
    m_maps.top()[name] = s;
 
85
}
 
86
 
 
87
void DecoderBase::mapEnd()
 
88
{
 
89
    ATLAS_DEBUG(std::cout << "DecoderBase::mapEnd" << std::endl)
 
90
    assert(!m_maps.empty());
 
91
    assert(!m_state.empty());
 
92
    m_state.pop();
 
93
    switch (m_state.top()) {
 
94
        case STATE_MAP:
 
95
            {
 
96
                MapType map = m_maps.top();
 
97
                m_maps.pop();
 
98
                assert(!m_maps.empty());
 
99
                assert(!m_names.empty());
 
100
                m_maps.top()[m_names.top()] = map;
 
101
                m_names.pop();
 
102
            }
 
103
            break;
 
104
        case STATE_LIST:
 
105
            {
 
106
                MapType map = m_maps.top();
 
107
                m_maps.pop();
 
108
                assert(!m_lists.empty());
 
109
                m_lists.top().insert(m_lists.top().end(), map);
 
110
            }
 
111
            break;
 
112
        case STATE_STREAM:
 
113
            {
 
114
                MapType & map = m_maps.top();
 
115
                messageArrived(map);
 
116
                m_maps.pop();
 
117
            }
 
118
            break;
 
119
        default:
 
120
            {
 
121
                // MapType map = m_maps.top();
 
122
                m_maps.pop();
 
123
            }
 
124
            break;
 
125
    }
 
126
}
 
127
 
 
128
void DecoderBase::listMapItem()
 
129
{
 
130
    ATLAS_DEBUG(std::cout << "DecoderBase::listMapItem" << std::endl)
 
131
    MapType map;
 
132
    m_maps.push(map);
 
133
    m_state.push(STATE_MAP);
 
134
}
 
135
 
 
136
void DecoderBase::listListItem()
 
137
{
 
138
    ATLAS_DEBUG(std::cout << "DecoderBase::listListItem" << std::endl)
 
139
    ListType list;
 
140
    m_lists.push(list);
 
141
    m_state.push(STATE_LIST);
 
142
}
 
143
 
 
144
void DecoderBase::listIntItem(long i)
 
145
{
 
146
    ATLAS_DEBUG(std::cout << "DecoderBase::listIntItem" << std::endl)
 
147
    assert(!m_lists.empty());       
 
148
    m_lists.top().push_back(i);
 
149
}
 
150
 
 
151
void DecoderBase::listFloatItem(double d)
 
152
{
 
153
    ATLAS_DEBUG(std::cout << "DecoderBase::listFloatItem" << std::endl)
 
154
    m_lists.top().push_back(d);
 
155
}
 
156
 
 
157
void DecoderBase::listStringItem(const std::string& s)
 
158
{
 
159
    ATLAS_DEBUG(std::cout << "DecoderBase::listStringItem" << std::endl)
 
160
    assert(!m_lists.empty());       
 
161
    m_lists.top().push_back(s);
 
162
}
 
163
 
 
164
void DecoderBase::listEnd()
 
165
{
 
166
    ATLAS_DEBUG(std::cout << "DecoderBase::listEnd" << std::endl)
 
167
    assert(!m_lists.empty());
 
168
    assert(!m_state.empty());
 
169
    ListType list = m_lists.top();
 
170
    m_lists.pop();
 
171
    m_state.pop();
 
172
    switch (m_state.top()) {
 
173
        case STATE_MAP:
 
174
            assert(!m_maps.empty());
 
175
            assert(!m_names.empty());
 
176
            m_maps.top()[m_names.top()] = list;
 
177
            m_names.pop();
 
178
            break;
 
179
        case STATE_LIST:
 
180
            assert(!m_lists.empty());
 
181
            m_lists.top().push_back(list);
 
182
            break;
 
183
        case STATE_STREAM:
 
184
            std::cerr << "DecoderBase::listEnd: Error" << std::endl;
 
185
            // XXX - report error?
 
186
            break;
 
187
    }
 
188
}
 
189
 
 
190
} } // namespace Atlas::Message