QuickFIX: /home/omiller/Development/autobuild/quickfix/src/C++/Queue.h Source File

Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

# Queue.h

Go to the documentation of this file.

    00001 /* -*- C++ -*- */
    00002
    00003 /****************************************************************************
    00004 ** Copyright (c) quickfixengine.org  All rights reserved.
    00005 **
    00006 ** This file is part of the QuickFIX FIX Engine
    00007 **
    00008 ** This file may be distributed under the terms of the quickfixengine.org
    00009 ** license as defined by quickfixengine.org and appearing in the file
    00010 ** LICENSE included in the packaging of this file.
    00011 **
    00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00014 **
    00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
    00016 **
    00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
    00018 ** not clear to you.
    00019 **
    00020 ****************************************************************************/
    00021
    00022 #ifndef FIX_QUEUE_H
    00023 #define FIX_QUEUE_H
    00024
    00025 #include "Utility.h"
    00026 #include "Event.h"
    00027 #include "Mutex.h"
    00028 #include <queue>
    00029
    00030 namespace FIX
    00031 {
    00033 template < typename T > class Queue
    00034 {
    00035 public:
    00036   void push( const T& value )
    00037   {
    00038     Locker locker( m_mutex );
    00039     m_queue.push( value );
    00040     signal();
    00041   }
    00042
    00043   bool pop( T& value )
    00044   {
    00045     Locker locker( m_mutex );
    00046     if ( !m_queue.size() ) return false;
    00047     value = m_queue.front();
    00048     m_queue.pop();
    00049     return true;
    00050   }
    00051
    00052   int size()
    00053   {
    00054     Locker locker( m_mutex );
    00055     return m_queue.size();
    00056   }
    00057
    00058   void wait()
    00059   {
    00060     m_event.wait();
    00061   }
    00062
    00063   void signal()
    00064   {
    00065     m_event.signal();
    00066   }
    00067
    00068 private:
    00069   Event m_event;
    00070   Mutex m_mutex;
    00071   std::queue < T > m_queue;
    00072 };
    00073 }
    00074
    00075 #endif