]> git.stg.codes - stg.git/blobdiff - include/stg/resetable.h
Various fixes of issues reported by static analyzers.
[stg.git] / include / stg / resetable.h
index f3cecac843b65ba94f85ffc023f945e7c8981c64..e7914efd3e90fdfc958025ac0317589d06735163 100644 (file)
@@ -1,9 +1,3 @@
- /*
- $Revision: 1.9 $
- $Date: 2010/03/11 14:42:04 $
- $Author: faust $
- */
-
 /*
  * Copyright (c) 2001 by Peter Simons <simons@cryp.to>.
  * All rights reserved.
@@ -15,8 +9,6 @@
 // This is a wrapper class about variables where you want to keep
 // track of whether it has been assigened yet or not.
 
-#include <iostream>
-
 template <typename T>
 class RESETABLE
 {
@@ -24,47 +16,37 @@ public:
     typedef T value_type;
 
     RESETABLE() : value(), is_set(false) {}
+    explicit RESETABLE(const T & v) : value(v), is_set(true) {}
 
-    RESETABLE(const RESETABLE<value_type> & rvalue)
-        : value(rvalue.value),
-          is_set(rvalue.is_set)
-    {}
-
-    RESETABLE(const value_type& val) : value(val), is_set(true) {}
-
-    RESETABLE<value_type> & operator=(const RESETABLE<value_type> & rvalue)
-    {
-        value = rvalue.value;
-        is_set = rvalue.is_set;
-        return *this;
-    }
-
-    RESETABLE<value_type> & operator=(const value_type& rhs)
+    RESETABLE<T> & operator=(const T & rhs)
     {
         value = rhs;
         is_set = true;
         return *this;
     }
 
-    const value_type & const_data() const throw() { return value; }
-    value_type & data() throw() { return value; }
-    operator const value_type&() const throw() { return value; }
-    bool res_empty() const throw() { return !is_set; }
+    const T & const_data() const throw() { return value; }
+    T & data() throw() { return value; }
+    const T & data() const throw() { return value; }
+    bool empty() const throw() { return !is_set; }
     void reset() throw() { is_set = false; }
+    void splice(const RESETABLE<T> & rhs)
+    {
+        if (rhs.is_set)
+        {
+            value = rhs.value;
+            is_set = true;
+        }
+    }
+    void maybeSet(value_type& dest) const
+    {
+        if (is_set)
+            dest = value;
+    }
 
 private:
     value_type value;
     bool       is_set;
 };
 
-template <typename T>
-std::ostream & operator<<(std::ostream & o, const RESETABLE<T> & v);
-
-template <typename T>
-inline
-std::ostream & operator<<(std::ostream & o, const RESETABLE<T> & v)
-{
-    return o << v.const_data();
-}
-
 #endif // RESETABLE_VARIABLE_H