CPN
Computational Process Networks
QueueAttr.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_QUEUEATTR_H
26 #define CPN_QUEUEATTR_H
27 #pragma once
28 
29 #include <cpn/common.h>
30 #include <cpn/QueueDatatypes.h>
31 #include <string>
32 
33 namespace CPN {
34 
56  public:
58  : queuehint(), datatype(TypeName<void>()),
59  queueLength(0), maxThreshold(0),
60  numChannels(1), alpha(0.5),
61  readerkey(0), writerkey(0), readernodekey(0), writernodekey(0),
62  maxwritethreshold(0)
63  {}
64 
65  QueueAttr(const unsigned queueLength_,
66  const unsigned maxThreshold_)
67  : queuehint(), datatype(TypeName<void>()),
68  queueLength(queueLength_), maxThreshold(maxThreshold_),
69  numChannels(1), alpha(0.5),
70  readerkey(0), writerkey(0), readernodekey(0), writernodekey(0),
71  maxwritethreshold(0)
72  {}
73 
80  QueueAttr &SetAlpha(double a) {
81  if (a < 0) { a = 0; }
82  else if (a > 1) { a = 1; }
83  alpha = a;
84  return *this;
85  }
86 
88  maxwritethreshold = mwt;
89  return *this;
90  }
91 
92  QueueAttr &SetName(const std::string &qname) {
93  queuename = qname;
94  return *this;
95  }
96 
97  QueueAttr &SetEndpoints(const std::string &readernode, const std::string &readerport,
98  const std::string &writernode, const std::string &writerport) {
99  SetReader(readernode, readerport);
100  SetWriter(writernode, writerport);
101  return *this;
102  }
103 
104  QueueAttr &SetExternalReader(const std::string &readername) {
105  return SetReader(readername, readername);
106  }
107 
108  QueueAttr &SetExternalWriter(const std::string &writername) {
109  return SetWriter(writername, writername);
110  }
111 
112  QueueAttr &SetReader(const std::string &nodename,
113  const std::string &portname) {
114  readernodename = nodename;
115  readerportname = portname;
116  return *this;
117  }
118 
120  const std::string &portname) {
121  readernodekey = nodekey;
122  readerportname = portname;
123  return *this;
124  }
125 
126  QueueAttr &SetWriter(const std::string &nodename,
127  const std::string &portname) {
128  writernodename = nodename;
129  writerportname = portname;
130  return *this;
131  }
132 
134  const std::string &portname) {
135  writernodekey = nodekey;
136  writerportname = portname;
137  return *this;
138  }
139 
146  QueueAttr &SetHint(std::string hint) {
147  queuehint = hint;
148  return *this;
149  }
150 
151  QueueAttr &SetDatatype(const std::string &type) {
152  datatype = type;
153  return *this;
154  }
155 
156  template<typename type>
158  datatype = TypeName<type>();
159  return *this;
160  }
161 
162  QueueAttr &SetLength(unsigned length) {
163  queueLength = length;
164  return *this;
165  }
166 
167  QueueAttr &SetMaxThreshold(unsigned maxthresh) {
168  maxThreshold = maxthresh;
169  return *this;
170  }
171 
172  QueueAttr &SetNumChannels(unsigned channels) {
173  numChannels = channels;
174  return *this;
175  }
176 
178  readernodekey = k;
179  return *this;
180  }
181 
183  writernodekey = k;
184  return *this;
185  }
186 
188  readerkey = k;
189  return *this;
190  }
191 
193  writerkey = k;
194  return *this;
195  }
196 
197  const std::string &GetWriterNode() const { return writernodename; }
198  const std::string &GetWriterPort() const { return writerportname; }
199  const std::string &GetReaderNode() const { return readernodename; }
200  const std::string &GetReaderPort() const { return readerportname; }
201  Key_t GetWriterNodeKey() const { return writernodekey; }
202  Key_t GetReaderNodeKey() const { return readernodekey; }
203  Key_t GetWriterKey() const { return writerkey; }
204  Key_t GetReaderKey() const { return readerkey; }
205  unsigned GetLength() const { return queueLength; }
206  unsigned GetMaxThreshold() const { return maxThreshold; }
207  unsigned GetNumChannels() const { return numChannels; }
208  std::string GetHint() const { return queuehint; }
209  const std::string &GetDatatype() const { return datatype; }
210  double GetAlpha() const { return alpha; }
211  const std::string &GetName() const { return queuename; }
212  unsigned GetMaxWriteThreshold() const { return maxwritethreshold; }
213 
214  private:
215  std::string queuehint;
216  std::string datatype;
217  std::string queuename;
218  unsigned queueLength;
219  unsigned maxThreshold;
220  unsigned numChannels;
221  double alpha;
222  std::string readernodename;
223  std::string readerportname;
224  std::string writernodename;
225  std::string writerportname;
231  };
232 
238  public:
240  : queuehint(),
241  queueLength(0), maxThreshold(0),
242  numChannels(0), alpha(0.5),
244  {}
246  : queuehint(attr.GetHint()),
247  datatype(attr.GetDatatype()),
248  queueLength(attr.GetLength()),
250  numChannels(attr.GetNumChannels()),
251  alpha(attr.GetAlpha()),
252  readerkey(attr.GetReaderKey()),
253  writerkey(attr.GetWriterKey()),
257  {}
258 
260  alpha = a;
261  return *this;
262  }
263 
265  maxwritethreshold = mwt;
266  return *this;
267  }
268 
269  SimpleQueueAttr &SetHint(std::string hint) {
270  queuehint = hint;
271  return *this;
272  }
273 
274  SimpleQueueAttr &SetDatatype(const std::string &type) {
275  datatype = type;
276  return *this;
277  }
278 
279  template<typename type>
281  datatype = TypeName<type>();
282  return *this;
283  }
284 
285  SimpleQueueAttr &SetLength(unsigned length) {
286  queueLength = length;
287  return *this;
288  }
289 
290  SimpleQueueAttr &SetMaxThreshold(unsigned maxthresh) {
291  maxThreshold = maxthresh;
292  return *this;
293  }
294 
295  SimpleQueueAttr &SetNumChannels(unsigned numchans) {
296  numChannels = numchans;
297  return *this;
298  }
299 
301  readernodekey = k;
302  return *this;
303  }
304 
306  writernodekey = k;
307  return *this;
308  }
309 
311  readerkey = k;
312  return *this;
313  }
314 
316  writerkey = k;
317  return *this;
318  }
319 
320 
323  Key_t GetWriterKey() const { return writerkey; }
324  Key_t GetReaderKey() const { return readerkey; }
325  unsigned GetLength() const { return queueLength; }
326  unsigned GetMaxThreshold() const { return maxThreshold; }
327  unsigned GetNumChannels() const { return numChannels; }
328  std::string GetHint() const { return queuehint; }
329  const std::string &GetDatatype() const { return datatype; }
330  double GetAlpha() const { return alpha; }
331  unsigned GetMaxWriteThreshold() const { return maxwritethreshold; }
332  private:
333  std::string queuehint;
334  std::string datatype;
335  unsigned queueLength;
336  unsigned maxThreshold;
337  unsigned numChannels;
338  double alpha;
344  };
345 }
346 #endif
unsigned GetLength() const
Definition: QueueAttr.h:325
unsigned queueLength
Definition: QueueAttr.h:218
unsigned queueLength
Definition: QueueAttr.h:335
QueueAttr & SetDatatype()
Definition: QueueAttr.h:157
SimpleQueueAttr & SetHint(std::string hint)
Definition: QueueAttr.h:269
QueueAttr & SetLength(unsigned length)
Definition: QueueAttr.h:162
unsigned numChannels
Definition: QueueAttr.h:337
QueueAttr & SetExternalReader(const std::string &readername)
Definition: QueueAttr.h:104
QueueAttr & SetNumChannels(unsigned channels)
Definition: QueueAttr.h:172
unsigned GetNumChannels() const
Definition: QueueAttr.h:327
Key_t GetWriterKey() const
Definition: QueueAttr.h:203
unsigned numChannels
Definition: QueueAttr.h:220
SimpleQueueAttr & SetDatatype()
Definition: QueueAttr.h:280
Key_t GetWriterKey() const
Definition: QueueAttr.h:323
SimpleQueueAttr & SetReaderNodeKey(Key_t k)
Definition: QueueAttr.h:300
SimpleQueueAttr & SetMaxWriteThreshold(unsigned mwt)
Definition: QueueAttr.h:264
unsigned maxThreshold
Definition: QueueAttr.h:219
const std::string & GetDatatype() const
Definition: QueueAttr.h:209
std::string GetHint() const
Definition: QueueAttr.h:208
std::string queuehint
Definition: QueueAttr.h:333
QueueAttr(const unsigned queueLength_, const unsigned maxThreshold_)
Definition: QueueAttr.h:65
std::string readernodename
Definition: QueueAttr.h:222
double GetAlpha() const
Definition: QueueAttr.h:210
unsigned GetMaxThreshold() const
Definition: QueueAttr.h:206
QueueAttr & SetMaxWriteThreshold(unsigned mwt)
Definition: QueueAttr.h:87
std::string queuehint
Definition: QueueAttr.h:215
QueueAttr & SetWriter(Key_t nodekey, const std::string &portname)
Definition: QueueAttr.h:133
QueueAttr & SetAlpha(double a)
alpha is used by the remote queue to decide how much of the queue should go on the read side and how ...
Definition: QueueAttr.h:80
Key_t readerkey
Definition: QueueAttr.h:226
const std::string & GetReaderPort() const
Definition: QueueAttr.h:200
SimpleQueueAttr & SetNumChannels(unsigned numchans)
Definition: QueueAttr.h:295
uint64_t Key_t
Definition: common.h:79
double alpha
Definition: QueueAttr.h:221
std::string TypeName()
unsigned GetNumChannels() const
Definition: QueueAttr.h:207
SimpleQueueAttr & SetLength(unsigned length)
Definition: QueueAttr.h:285
QueueAttr & SetReader(Key_t nodekey, const std::string &portname)
Definition: QueueAttr.h:119
unsigned GetLength() const
Definition: QueueAttr.h:205
SimpleQueueAttr & SetAlpha(double a)
Definition: QueueAttr.h:259
QueueAttr & SetDatatype(const std::string &type)
Definition: QueueAttr.h:151
std::string writerportname
Definition: QueueAttr.h:225
const std::string & GetWriterNode() const
Definition: QueueAttr.h:197
double GetAlpha() const
Definition: QueueAttr.h:330
unsigned maxThreshold
Definition: QueueAttr.h:336
unsigned GetMaxThreshold() const
Definition: QueueAttr.h:326
QueueAttr & SetExternalWriter(const std::string &writername)
Definition: QueueAttr.h:108
std::string readerportname
Definition: QueueAttr.h:223
QueueAttr & SetReaderKey(Key_t k)
Definition: QueueAttr.h:187
Key_t writernodekey
Definition: QueueAttr.h:229
std::string datatype
Definition: QueueAttr.h:216
unsigned GetMaxWriteThreshold() const
Definition: QueueAttr.h:212
QueueAttr & SetEndpoints(const std::string &readernode, const std::string &readerport, const std::string &writernode, const std::string &writerport)
Definition: QueueAttr.h:97
std::string queuename
Definition: QueueAttr.h:217
const std::string & GetName() const
Definition: QueueAttr.h:211
QueueAttr & SetReader(const std::string &nodename, const std::string &portname)
Definition: QueueAttr.h:112
Key_t GetReaderKey() const
Definition: QueueAttr.h:324
SimpleQueueAttr(const QueueAttr &attr)
Definition: QueueAttr.h:245
std::string writernodename
Definition: QueueAttr.h:224
QueueAttr & SetWriterKey(Key_t k)
Definition: QueueAttr.h:192
QueueAttr & SetMaxThreshold(unsigned maxthresh)
Definition: QueueAttr.h:167
QueueAttr & SetWriter(const std::string &nodename, const std::string &portname)
Definition: QueueAttr.h:126
const std::string & GetWriterPort() const
Definition: QueueAttr.h:198
Key_t GetReaderKey() const
Definition: QueueAttr.h:204
std::string datatype
Definition: QueueAttr.h:334
SimpleQueueAttr & SetWriterNodeKey(Key_t k)
Definition: QueueAttr.h:305
Key_t GetWriterNodeKey() const
Definition: QueueAttr.h:321
Key_t writerkey
Definition: QueueAttr.h:227
QueueAttr & SetReaderNodeKey(Key_t k)
Definition: QueueAttr.h:177
unsigned maxwritethreshold
Definition: QueueAttr.h:343
QueueAttr & SetHint(std::string hint)
Definition: QueueAttr.h:146
const std::string & GetDatatype() const
Definition: QueueAttr.h:329
const std::string & GetReaderNode() const
Definition: QueueAttr.h:199
The attributes for a queue.
Definition: QueueAttr.h:55
#define CPN_API
Definition: common.h:36
SimpleQueueAttr & SetWriterKey(Key_t k)
Definition: QueueAttr.h:315
unsigned GetMaxWriteThreshold() const
Definition: QueueAttr.h:331
SimpleQueueAttr & SetDatatype(const std::string &type)
Definition: QueueAttr.h:274
Key_t GetReaderNodeKey() const
Definition: QueueAttr.h:322
std::string GetHint() const
Definition: QueueAttr.h:328
SimpleQueueAttr & SetMaxThreshold(unsigned maxthresh)
Definition: QueueAttr.h:290
This is a simplified internal representation of the queue attributes needed to create a queue...
Definition: QueueAttr.h:237
QueueAttr & SetName(const std::string &qname)
Definition: QueueAttr.h:92
Key_t readernodekey
Definition: QueueAttr.h:228
unsigned maxwritethreshold
Definition: QueueAttr.h:230
QueueAttr & SetWriterNodeKey(Key_t k)
Definition: QueueAttr.h:182
Key_t GetWriterNodeKey() const
Definition: QueueAttr.h:201
Key_t GetReaderNodeKey() const
Definition: QueueAttr.h:202
SimpleQueueAttr & SetReaderKey(Key_t k)
Definition: QueueAttr.h:310
Defintions of and helper functions for queue datatypes.