DescriptorSet.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_DESCRIPTOR_SET_H
10 #define SQUID_DESCRIPTOR_SET_H
11 
12 #include <iosfwd>
13 
21 {
22 public:
23  // for STL compatibility, should we decide to switch to std::set or similar
24  typedef const int *const_iterator;
25 
26  DescriptorSet();
28 
30  bool has(const int fd) const {
31  return 0 <= fd && fd < capacity_ &&
32  index_[fd] >= 0;
33  }
34 
35  bool add(int fd);
36  bool del(int fd);
37  int pop();
38 
39  bool empty() const { return !size_; }
40 
42  const_iterator begin() const { return descriptors_; }
44  const_iterator end() const { return begin() + size_; }
45 
47  void print(std::ostream &os) const;
48 
49 private:
50  // these would be easy to support when needed; prohibit for now
51  DescriptorSet(const DescriptorSet &s); // declared but undefined
52  DescriptorSet &operator =(const DescriptorSet &s); // declared, undefined
53 
54  int *descriptors_;
55  int *index_;
56  int capacity_;
57  int size_;
58 };
59 
61 inline std::ostream &
62 operator <<(std::ostream &os, const DescriptorSet &ds)
63 {
64  ds.print(os);
65  return os;
66 }
67 
68 #endif /* SQUID_DESCRIPTOR_SET_H */
69 
void print(std::ostream &os) const
outputs debugging info about the set
bool del(int fd)
deletes if there; returns true if deleted
int size_
number of descriptors in the set
Definition: DescriptorSet.h:57
const int * const_iterator
Definition: DescriptorSet.h:24
const_iterator end() const
end iterator a la STL; may become invalid if the object is modified
Definition: DescriptorSet.h:44
bool empty() const
number of descriptors in the set
Definition: DescriptorSet.h:39
const_iterator begin() const
begin iterator a la STL; may become invalid if the object is modified
Definition: DescriptorSet.h:42
DescriptorSet & operator=(const DescriptorSet &s)
int capacity_
total number of descriptor slots
Definition: DescriptorSet.h:56
int * descriptors_
descriptor values in random order
Definition: DescriptorSet.h:54
int * index_
descriptor:position index into descriptors_
Definition: DescriptorSet.h:55
std::ostream & operator<<(std::ostream &os, const DescriptorSet &ds)
convenience wrapper to be used in debugs() context
Definition: DescriptorSet.h:62
int pop()
deletes and returns one descriptor, in unspecified order
bool has(const int fd) const
checks whether fd is in the set
Definition: DescriptorSet.h:30
bool add(int fd)
adds if unique; returns true if added

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors