File: DecoderBase.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 (190 lines) | stat: -rw-r--r-- 4,756 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// 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/DecoderBase.h>

#include <Atlas/Message/Element.h>

#include <Atlas/Debug.h>

#include <iostream>

#include <cassert>

static const bool debug_flag = false;

namespace Atlas { namespace Message {

DecoderBase::DecoderBase()
{
}

DecoderBase::~DecoderBase()
{
}

void DecoderBase::streamBegin()
{
    ATLAS_DEBUG(std::cout << "DecoderBase::streamBegin" << std::endl)
    m_state.push(STATE_STREAM);
}

void DecoderBase::streamMessage()
{
    ATLAS_DEBUG(std::cout << "DecoderBase::streamMessage" << std::endl)
    MapType m;
    m_maps.push(m);
    m_state.push(STATE_MAP);
}

void DecoderBase::streamEnd()
{
    ATLAS_DEBUG(std::cout << "DecoderBase::streamEnd" << std::endl)
    assert(!m_state.empty());
    m_state.pop();
}

void DecoderBase::mapMapItem(const std::string& name)
{
    ATLAS_DEBUG(std::cout << "DecoderBase::mapMapItem Map" << std::endl)
    MapType m;
    m_names.push(name);
    m_maps.push(m);
    m_state.push(STATE_MAP);
}

void DecoderBase::mapListItem(const std::string& name)
{
    ATLAS_DEBUG(std::cout << "DecoderBase::mapListItem List" << std::endl)
    ListType l;
    m_names.push(name);
    m_lists.push(l);
    m_state.push(STATE_LIST);
}

void DecoderBase::mapIntItem(const std::string& name, long i)
{
    ATLAS_DEBUG(std::cout << "DecoderBase::mapIntItem" << std::endl)
    assert(!m_maps.empty());        
    m_maps.top()[name] = i;
}

void DecoderBase::mapFloatItem(const std::string& name, double d)
{
    ATLAS_DEBUG(std::cout << "DecoderBase::mapFloatItem" << std::endl)
    assert(!m_maps.empty());       
    m_maps.top()[name] = d;
}

void DecoderBase::mapStringItem(const std::string& name, const std::string& s)
{
    ATLAS_DEBUG(std::cout << "DecoderBase::mapStringItem" << std::endl)
    assert(!m_maps.empty());
    m_maps.top()[name] = s;
}

void DecoderBase::mapEnd()
{
    ATLAS_DEBUG(std::cout << "DecoderBase::mapEnd" << std::endl)
    assert(!m_maps.empty());
    assert(!m_state.empty());
    m_state.pop();
    switch (m_state.top()) {
        case STATE_MAP:
            {
                MapType map = m_maps.top();
                m_maps.pop();
                assert(!m_maps.empty());
                assert(!m_names.empty());
                m_maps.top()[m_names.top()] = map;
                m_names.pop();
            }
            break;
        case STATE_LIST:
            {
                MapType map = m_maps.top();
                m_maps.pop();
                assert(!m_lists.empty());
                m_lists.top().insert(m_lists.top().end(), map);
            }
            break;
        case STATE_STREAM:
            {
                MapType & map = m_maps.top();
                messageArrived(map);
                m_maps.pop();
            }
            break;
        default:
            {
                // MapType map = m_maps.top();
                m_maps.pop();
            }
            break;
    }
}

void DecoderBase::listMapItem()
{
    ATLAS_DEBUG(std::cout << "DecoderBase::listMapItem" << std::endl)
    MapType map;
    m_maps.push(map);
    m_state.push(STATE_MAP);
}

void DecoderBase::listListItem()
{
    ATLAS_DEBUG(std::cout << "DecoderBase::listListItem" << std::endl)
    ListType list;
    m_lists.push(list);
    m_state.push(STATE_LIST);
}

void DecoderBase::listIntItem(long i)
{
    ATLAS_DEBUG(std::cout << "DecoderBase::listIntItem" << std::endl)
    assert(!m_lists.empty());       
    m_lists.top().push_back(i);
}

void DecoderBase::listFloatItem(double d)
{
    ATLAS_DEBUG(std::cout << "DecoderBase::listFloatItem" << std::endl)
    m_lists.top().push_back(d);
}

void DecoderBase::listStringItem(const std::string& s)
{
    ATLAS_DEBUG(std::cout << "DecoderBase::listStringItem" << std::endl)
    assert(!m_lists.empty());       
    m_lists.top().push_back(s);
}

void DecoderBase::listEnd()
{
    ATLAS_DEBUG(std::cout << "DecoderBase::listEnd" << std::endl)
    assert(!m_lists.empty());
    assert(!m_state.empty());
    ListType list = m_lists.top();
    m_lists.pop();
    m_state.pop();
    switch (m_state.top()) {
        case STATE_MAP:
            assert(!m_maps.empty());
            assert(!m_names.empty());
            m_maps.top()[m_names.top()] = list;
            m_names.pop();
            break;
        case STATE_LIST:
            assert(!m_lists.empty());
            m_lists.top().push_back(list);
            break;
        case STATE_STREAM:
            std::cerr << "DecoderBase::listEnd: Error" << std::endl;
            // XXX - report error?
            break;
    }
}

} } // namespace Atlas::Message