]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/mem/Page.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / mem / Page.h
index e7ff8c5667bf61a1604772feb691d115ce17f103..5b98e72980dced876e77757b223712efa8e30368 100644 (file)
@@ -1,12 +1,15 @@
 /*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_IPC_MEM_PAGE_H
 #define SQUID_IPC_MEM_PAGE_H
 
-#if HAVE_IOSFWD
 #include <iosfwd>
-#endif
 
 namespace Ipc
 {
@@ -20,7 +23,12 @@ class PageId
 public:
     PageId(): pool(0), number(0), purpose(maxPurpose) {}
 
-    operator bool() const { return pool && number; }
+    /// true if and only if both critical components have been initialized
+    bool set() const { return pool && number; }
+
+    // safer than bool which would enable silent casts to int
+    typedef const uint32_t PageId::*SaferBool;
+    operator SaferBool() const { return set() ? &PageId::number : NULL; }
 
     uint32_t pool; ///< page pool ID within Squid
     // uint32_t segment; ///< memory segment ID within the pool; unused for now
@@ -38,3 +46,4 @@ std::ostream &operator <<(std::ostream &os, const PageId &page);
 } // namespace Ipc
 
 #endif // SQUID_IPC_MEM_PAGE_H
+