Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXPtrQueue.h
1 /********************************************************************************
2 * *
3 * Q u e u e O f P o i n t e r s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2006,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXPTRQUEUE_H
22 #define FXPTRQUEUE_H
23 
24 namespace FX {
25 
26 
28 class FXAPI FXPtrQueue {
29 private:
30  FXPtrList list; // List of pointers
31  volatile FXival head; // Write side
32  volatile FXival tail; // Read side
33 private:
34  FXPtrQueue(const FXPtrQueue&);
35  FXPtrQueue &operator=(const FXPtrQueue&);
36 public:
37 
39  FXPtrQueue();
40 
42  FXPtrQueue(FXival sz);
43 
45  FXbool setSize(FXival sz);
46 
48  FXival getSize() const { return list.no(); }
49 
51  FXival getUsed() const;
52 
54  FXival getFree() const;
55 
57  FXbool isFull() const;
58 
60  FXbool isEmpty() const;
61 
63  FXbool push(FXptr ptr);
64 
66  FXbool peek(FXptr& ptr);
67 
69  FXbool pop(FXptr& ptr);
70 
72  FXbool pop();
73 
75  ~FXPtrQueue();
76  };
77 
78 
80 template <typename TYPE>
81 class FXPtrQueueOf : public FXPtrQueue {
82 public:
83  FXPtrQueueOf(){}
84  FXPtrQueueOf(FXuint sz):FXPtrQueue(sz){}
85  FXbool push(TYPE* ptr){ return FXPtrQueue::push((FXptr)ptr); }
86  FXbool peek(TYPE*& ptr){ return FXPtrQueue::peek((FXptr&)ptr); }
87  FXbool pop(TYPE*& ptr){ return FXPtrQueue::pop((FXptr&)ptr); }
88  };
89 
90 }
91 
92 #endif
Queue of pointers to TYPE.
Definition: FXPtrQueue.h:81
Queue of void pointers.
Definition: FXPtrQueue.h:28
FXbool push(FXptr ptr)
Add item to queue, return true if success.
FXbool pop()
Drop item from queue, return true if success.
Definition: FX4Splitter.h:28
FXival no() const
Return number of objects.
Definition: FXPtrList.h:55
FXbool peek(FXptr &ptr)
Peek for item.
FXival getSize() const
Return size.
Definition: FXPtrQueue.h:48
List of void pointers.
Definition: FXPtrList.h:28
FXPtrQueue()
Create initially empty queue.

Copyright © 1997-2022 Jeroen van der Zijp