InstanceId.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_BASE_INSTANCE_ID_H
10 #define SQUID_BASE_INSTANCE_ID_H
11 
12 #include <iosfwd>
13 
22 template <class Class>
24 {
25 public:
26  typedef unsigned int Value;
27 
29 
30  operator Value() const { return value; }
31  bool operator ==(const InstanceId &o) const { return value == o.value; }
32  bool operator !=(const InstanceId &o) const { return !(*this == o); }
33  void change();
34 
36  std::ostream &print(std::ostream &) const;
37 
39  const char * prefix() const;
40 
41 public:
42  Value value = 0;
43 
44 private:
45  InstanceId(const InstanceId &);
46  InstanceId& operator=(const InstanceId &);
47 };
48 
50 #define InstanceIdDefinitions(Class, pfx) \
51  template<> const char * \
52  InstanceId<Class>::prefix() const { \
53  return pfx; \
54  } \
55  template<> std::ostream & \
56  InstanceId<Class>::print(std::ostream &os) const { \
57  return os << pfx << value; \
58  } \
59  template<> void \
60  InstanceId<Class>::change() { \
61  static InstanceId<Class>::Value Last = 0; \
62  value = ++Last ? Last : ++Last; \
63  }
64 
66 template <class Class>
67 inline
68 std::ostream &operator <<(std::ostream &os, const InstanceId<Class> &id)
69 {
70  return id.print(os);
71 }
72 
73 #endif /* SQUID_BASE_INSTANCE_ID_H */
74 
std::ostream & print(std::ostream &) const
prints class-pecific prefix followed by ID value;
unsigned int Value
id storage type;
Definition: InstanceId.h:26
void change()
Value value
instance identifier
Definition: InstanceId.h:42
bool operator!=(const InstanceId &o) const
Definition: InstanceId.h:32
bool operator==(const InstanceId &o) const
Definition: InstanceId.h:31
const char * prefix() const
returns the class-pecific prefix
InstanceId & operator=(const InstanceId &)
not implemented

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors