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
5
#include <Atlas/Message/DecoderBase.h>
7
#include <Atlas/Message/Element.h>
9
#include <Atlas/Debug.h>
15
static const bool debug_flag = false;
17
namespace Atlas { namespace Message {
19
DecoderBase::DecoderBase()
23
DecoderBase::~DecoderBase()
27
void DecoderBase::streamBegin()
29
ATLAS_DEBUG(std::cout << "DecoderBase::streamBegin" << std::endl)
30
m_state.push(STATE_STREAM);
33
void DecoderBase::streamMessage()
35
ATLAS_DEBUG(std::cout << "DecoderBase::streamMessage" << std::endl)
38
m_state.push(STATE_MAP);
41
void DecoderBase::streamEnd()
43
ATLAS_DEBUG(std::cout << "DecoderBase::streamEnd" << std::endl)
44
assert(!m_state.empty());
48
void DecoderBase::mapMapItem(const std::string& name)
50
ATLAS_DEBUG(std::cout << "DecoderBase::mapMapItem Map" << std::endl)
54
m_state.push(STATE_MAP);
57
void DecoderBase::mapListItem(const std::string& name)
59
ATLAS_DEBUG(std::cout << "DecoderBase::mapListItem List" << std::endl)
63
m_state.push(STATE_LIST);
66
void DecoderBase::mapIntItem(const std::string& name, long i)
68
ATLAS_DEBUG(std::cout << "DecoderBase::mapIntItem" << std::endl)
69
assert(!m_maps.empty());
70
m_maps.top()[name] = i;
73
void DecoderBase::mapFloatItem(const std::string& name, double d)
75
ATLAS_DEBUG(std::cout << "DecoderBase::mapFloatItem" << std::endl)
76
assert(!m_maps.empty());
77
m_maps.top()[name] = d;
80
void DecoderBase::mapStringItem(const std::string& name, const std::string& s)
82
ATLAS_DEBUG(std::cout << "DecoderBase::mapStringItem" << std::endl)
83
assert(!m_maps.empty());
84
m_maps.top()[name] = s;
87
void DecoderBase::mapEnd()
89
ATLAS_DEBUG(std::cout << "DecoderBase::mapEnd" << std::endl)
90
assert(!m_maps.empty());
91
assert(!m_state.empty());
93
switch (m_state.top()) {
96
MapType map = m_maps.top();
98
assert(!m_maps.empty());
99
assert(!m_names.empty());
100
m_maps.top()[m_names.top()] = map;
106
MapType map = m_maps.top();
108
assert(!m_lists.empty());
109
m_lists.top().insert(m_lists.top().end(), map);
114
MapType & map = m_maps.top();
121
// MapType map = m_maps.top();
128
void DecoderBase::listMapItem()
130
ATLAS_DEBUG(std::cout << "DecoderBase::listMapItem" << std::endl)
133
m_state.push(STATE_MAP);
136
void DecoderBase::listListItem()
138
ATLAS_DEBUG(std::cout << "DecoderBase::listListItem" << std::endl)
141
m_state.push(STATE_LIST);
144
void DecoderBase::listIntItem(long i)
146
ATLAS_DEBUG(std::cout << "DecoderBase::listIntItem" << std::endl)
147
assert(!m_lists.empty());
148
m_lists.top().push_back(i);
151
void DecoderBase::listFloatItem(double d)
153
ATLAS_DEBUG(std::cout << "DecoderBase::listFloatItem" << std::endl)
154
m_lists.top().push_back(d);
157
void DecoderBase::listStringItem(const std::string& s)
159
ATLAS_DEBUG(std::cout << "DecoderBase::listStringItem" << std::endl)
160
assert(!m_lists.empty());
161
m_lists.top().push_back(s);
164
void DecoderBase::listEnd()
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();
172
switch (m_state.top()) {
174
assert(!m_maps.empty());
175
assert(!m_names.empty());
176
m_maps.top()[m_names.top()] = list;
180
assert(!m_lists.empty());
181
m_lists.top().push_back(list);
184
std::cerr << "DecoderBase::listEnd: Error" << std::endl;
185
// XXX - report error?
190
} } // namespace Atlas::Message