X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/9701b7ab4dc4cd709ad4dcaa750fc0021f15e231..1890cc7d2037b5ea90e67a63b24b377244565322:/include/stg/resetable.h diff --git a/include/stg/resetable.h b/include/stg/resetable.h index d31bffda..8a6ad27c 100644 --- a/include/stg/resetable.h +++ b/include/stg/resetable.h @@ -1,9 +1,3 @@ - /* - $Revision: 1.9 $ - $Date: 2010/03/11 14:42:04 $ - $Author: faust $ - */ - /* * Copyright (c) 2001 by Peter Simons . * All rights reserved. @@ -15,84 +9,51 @@ // This is a wrapper class about variables where you want to keep // track of whether it has been assigened yet or not. -#include - -template +template class RESETABLE { - template - friend std::ostream & operator<<(std::ostream & o, RESETABLE v); public: - typedef varT value_type; + typedef T value_type; - //------------------------------------------------------------------------- - RESETABLE() - : value(), - is_set(false) - { - } - //------------------------------------------------------------------------- - RESETABLE(const RESETABLE & rvalue) + RESETABLE() : value(), is_set(false) {} + RESETABLE(const T & v) : value(v), is_set(true) {} + + RESETABLE(const RESETABLE & rvalue) : value(rvalue.value), is_set(rvalue.is_set) + {} + + RESETABLE & operator=(const RESETABLE & rhs) { - } - //------------------------------------------------------------------------- - RESETABLE(const value_type& val) - : value(val), - is_set(true) - { - } - //------------------------------------------------------------------------- - RESETABLE & operator=(const RESETABLE & rvalue) - { - value = rvalue.value; - is_set = rvalue.is_set; + value = rhs.value; + is_set = rhs.is_set; return *this; } - //------------------------------------------------------------------------- - RESETABLE & operator= (const value_type& rhs) + + RESETABLE & 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; - } - //------------------------------------------------------------------------- - void reset() throw() - { - is_set = false; + + 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 & rhs) + { + if (rhs.is_set) + { + value = rhs.value; + is_set = true; + } } - //------------------------------------------------------------------------- -protected: - value_type value; - bool is_set; + +private: + value_type value; + bool is_set; }; -//----------------------------------------------------------------------------- -template -std::ostream & operator<<(std::ostream & o, RESETABLE v) -{ - return o << v.value; -} -//------------------------------------------------------------------------- -#endif // RESETABLE_VARIABLE_H +#endif // RESETABLE_VARIABLE_H