CPN
Computational Process Networks
OQueue.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 //=============================================================================
26 #ifndef CPN_QUEUE_QUEUEWRITERADAPTOR_H
27 #define CPN_QUEUE_QUEUEWRITERADAPTOR_H
28 #pragma once
29 
30 #include <cpn/common.h>
31 #include <cpn/bits/QueueWriter.h>
32 #include <cpn/QueueDatatypes.h>
33 #include <cpn/Exceptions.h>
34 
35 namespace CPN {
40  template<class T>
41  class OQueue {
42  public:
43  OQueue() {}
44  OQueue(shared_ptr<QueueWriter> q) : queue(q) {
45  if (!TypeCompatable(TypeName<T>(), queue->GetDatatype())) {
46  throw TypeMismatchException(TypeName<T>(), queue->GetDatatype());
47  }
48  }
49 
56  T* GetEnqueuePtr(unsigned thresh, unsigned chan=0) {
57  return (T*) queue->GetRawEnqueuePtr(GetTypeSize<T>() * thresh, chan);
58  }
59 
64  void Enqueue(unsigned count) {
65  queue->Enqueue(GetTypeSize<T>() * count);
66  }
67 
73  void Enqueue(const T* data, unsigned count) {
74  queue->RawEnqueue((void*)data, GetTypeSize<T>() * count);
75  }
76 
84  void Enqueue(const T* data, unsigned count, unsigned numChans, unsigned chanStride) {
85  queue->RawEnqueue((void*)data, GetTypeSize<T>() * count,
86  numChans, GetTypeSize<T>() * chanStride);
87  }
88 
89  void Flush() { queue->Flush(); }
90  bool Flushed() { return queue->Flushed(); }
91 
93  unsigned NumChannels() const { return queue->NumChannels(); }
95  unsigned MaxThreshold() const { return queue->MaxThreshold()/GetTypeSize<T>(); }
96  unsigned QueueLength() const { return queue->QueueLength()/GetTypeSize<T>(); }
98  unsigned Freespace() const { return queue->Freespace()/GetTypeSize<T>(); }
100  unsigned ChannelStride() const { return queue->ChannelStride()/GetTypeSize<T>(); }
102  bool Full() const { return queue->Full(); }
104  Key_t GetKey() const { return queue->GetKey(); }
106  shared_ptr<QueueWriter> GetWriter() { return queue; }
108  void Release() { queue->Release(); queue.reset(); }
109 
110  private:
111  shared_ptr<QueueWriter> queue;
112  };
113 }
114 #endif
T * GetEnqueuePtr(unsigned thresh, unsigned chan=0)
Definition: OQueue.h:56
OQueue()
Definition: OQueue.h:43
A template class to do type conversion for the writer end of the queue.
Definition: OQueue.h:41
unsigned QueueLength() const
Definition: OQueue.h:96
unsigned NumChannels() const
Definition: OQueue.h:93
void Enqueue(unsigned count)
Definition: OQueue.h:64
void Release()
Release the writer, further operations are invalid.
Definition: OQueue.h:108
bool Full() const
Definition: OQueue.h:102
uint64_t Key_t
Definition: common.h:79
The exceptions specified for the CPN network.
Key_t GetKey() const
Definition: OQueue.h:104
void Flush()
Definition: OQueue.h:89
void Enqueue(const T *data, unsigned count, unsigned numChans, unsigned chanStride)
Definition: OQueue.h:84
An exception indicating that there is a type mismatch in the queue.
Definition: Exceptions.h:49
shared_ptr< QueueWriter > queue
Definition: OQueue.h:111
Definition for the Queue writer inteface.
bool TypeCompatable(const std::string &type1, const std::string &type2)
unsigned Freespace() const
Definition: OQueue.h:98
bool Flushed()
Definition: OQueue.h:90
shared_ptr< QueueWriter > GetWriter()
Definition: OQueue.h:106
unsigned ChannelStride() const
Definition: OQueue.h:100
unsigned MaxThreshold() const
Definition: OQueue.h:95
void Enqueue(const T *data, unsigned count)
Definition: OQueue.h:73
OQueue(shared_ptr< QueueWriter > q)
Definition: OQueue.h:44
Defintions of and helper functions for queue datatypes.