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 // $Id$
6 
7 #ifndef ATLAS_MESSAGE_QUEUEDDECODER_H
8 #define ATLAS_MESSAGE_QUEUEDDECODER_H
9 
10 #include <Atlas/Message/DecoderBase.h>
11 #include <Atlas/Message/Element.h>
12 
13 #include <queue>
14 
15 namespace Atlas { namespace Message {
16 
17 class Element;
18 
19 typedef std::map<std::string, Element> MapType;
20 
21 /** Decoder that presents a queue of Atlas::Message::Element.
22  *
23  * This message decoder puts arrived objects into a queue and allows the
24  * application to pop them off the front of the queue, peek at the front of
25  * the queue, as well as checking to see how many objects are currently in the
26  * queue.
27  *
28  * @see DecoderBase
29  * @see Element
30  * @author Stefanus Du Toit <sdt@gmx.net>
31  *
32  */
33 
34 class QueuedDecoder : public DecoderBase
35 {
36 public:
37 
38     QueuedDecoder();
39 
40     /// Retrieve the current size of the message queue.
queueSize()41     size_t queueSize() {
42 	return m_objectQueue.size();
43     }
44     /// Pop an object from the front of the message queue.
popMessage()45     const MapType popMessage() {
46         MapType r = m_objectQueue.front();
47         m_objectQueue.pop();
48         return r;
49     }
50     /// Peek at the object at the front of the queue.
frontMessage()51     const MapType frontMessage() {
52 	return m_objectQueue.front();
53     }
54     /// Clear the message queue.
55     void clearQueue();
56 
57 protected:
58 
59     /// This adds a message to the queue.
60     void messageArrived(const MapType& obj);
61 
62 private:
63 
64     std::queue<MapType> m_objectQueue;
65 };
66 
67 } } // namespace Atlas::Message
68 
69 #endif
70