CPN
Computational Process Networks
IQueue.h
Go to the documentation of this file.
1 //=============================================================================
2 // Computational Process Networks class library
3 // Copyright (C) 1997-2006 Gregory E. Allen and The University of Texas
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Library General Public License as published
7 // by the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
14 //
15 // The GNU Public License is available in the file LICENSE, or you
16 // can write to the Free Software Foundation, Inc., 59 Temple Place -
17 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
18 // World Wide Web at http://www.fsf.org.
19 //=============================================================================
25 #ifndef CPN_QUEUE_QUEUEREADERADAPTER_H
26 #define CPN_QUEUE_QUEUEREADERADAPTER_H
27 #pragma once
28 
29 #include <cpn/common.h>
30 #include <cpn/bits/QueueReader.h>
31 #include <cpn/QueueDatatypes.h>
32 #include <cpn/Exceptions.h>
33 
34 namespace CPN {
38  template<class T>
39  class IQueue {
40  public:
41  IQueue() {}
42  IQueue(shared_ptr<QueueReader> q) : queue(q) {
43  if (!TypeCompatable(TypeName<T>(), queue->GetDatatype())) {
44  throw TypeMismatchException(TypeName<T>(), queue->GetDatatype());
45  }
46  }
47 
55  const T* GetDequeuePtr(unsigned thresh, unsigned chan=0) {
56  return (T*) queue->GetRawDequeuePtr(GetTypeSize<T>() * thresh, chan);
57  }
58 
63  void Dequeue(unsigned count) {
64  queue->Dequeue(GetTypeSize<T>() * count);
65  }
66 
73  bool Dequeue(T* data, unsigned count) {
74  return queue->RawDequeue((void*)data, GetTypeSize<T>() * count);
75  }
76 
85  bool Dequeue(T* data, unsigned count, unsigned numChans, unsigned chanStride) {
86  return queue->RawDequeue((void*)data, GetTypeSize<T>() * count,
87  numChans, GetTypeSize<T>() * chanStride);
88  }
89 
90  void Reset() { queue->Reset(); }
91  bool Flushed() { return queue->Flushed(); }
92 
94  unsigned NumChannels() const { return queue->NumChannels(); }
96  unsigned MaxThreshold() const { return queue->MaxThreshold()/GetTypeSize<T>(); }
97  unsigned QueueLength() const { return queue->QueueLength()/GetTypeSize<T>(); }
99  unsigned Count() const { return queue->Count()/GetTypeSize<T>(); }
101  bool Empty() const { return queue->Empty(); }
103  unsigned ChannelStride() const { return queue->ChannelStride()/GetTypeSize<T>(); }
105  Key_t GetKey() const { return queue->GetKey(); }
107  shared_ptr<QueueReader> GetReader() { return queue; }
109  void Release() { queue->Release(); queue.reset(); }
110  private:
111  shared_ptr<QueueReader> queue;
112  };
113 }
114 #endif
bool Flushed()
Definition: IQueue.h:91
shared_ptr< QueueReader > GetReader()
Definition: IQueue.h:107
const T * GetDequeuePtr(unsigned thresh, unsigned chan=0)
Definition: IQueue.h:55
unsigned QueueLength() const
Definition: IQueue.h:97
IQueue()
Definition: IQueue.h:41
shared_ptr< QueueReader > queue
Definition: IQueue.h:111
uint64_t Key_t
Definition: common.h:79
bool Dequeue(T *data, unsigned count)
Definition: IQueue.h:73
The exceptions specified for the CPN network.
bool Dequeue(T *data, unsigned count, unsigned numChans, unsigned chanStride)
Definition: IQueue.h:85
An exception indicating that there is a type mismatch in the queue.
Definition: Exceptions.h:49
unsigned Count() const
Definition: IQueue.h:99
bool Empty() const
Definition: IQueue.h:101
The definition of reader end of the queue.
void Release()
Release this reader all further actions are invalid.
Definition: IQueue.h:109
Template class to do type conversion for reader end of the queue.
Definition: IQueue.h:39
bool TypeCompatable(const std::string &type1, const std::string &type2)
unsigned ChannelStride() const
Definition: IQueue.h:103
unsigned MaxThreshold() const
Definition: IQueue.h:96
void Reset()
Definition: IQueue.h:90
Key_t GetKey() const
Definition: IQueue.h:105
unsigned NumChannels() const
Definition: IQueue.h:94
IQueue(shared_ptr< QueueReader > q)
Definition: IQueue.h:42
void Dequeue(unsigned count)
Definition: IQueue.h:63
Defintions of and helper functions for queue datatypes.