diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /sp/src/public/tier1/rangecheckedvar.h | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'sp/src/public/tier1/rangecheckedvar.h')
| -rw-r--r-- | sp/src/public/tier1/rangecheckedvar.h | 236 |
1 files changed, 118 insertions, 118 deletions
diff --git a/sp/src/public/tier1/rangecheckedvar.h b/sp/src/public/tier1/rangecheckedvar.h index 8d9eba70..52313f82 100644 --- a/sp/src/public/tier1/rangecheckedvar.h +++ b/sp/src/public/tier1/rangecheckedvar.h @@ -1,118 +1,118 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-//=============================================================================//
-
-#ifndef RANGECHECKEDVAR_H
-#define RANGECHECKEDVAR_H
-#ifdef _WIN32
-#pragma once
-#endif
-
-
-#include "tier0/dbg.h"
-#include "tier0/threadtools.h"
-#include "mathlib/vector.h"
-#include <float.h>
-
-
-// Use this to disable range checks within a scope.
-class CDisableRangeChecks
-{
-public:
- CDisableRangeChecks();
- ~CDisableRangeChecks();
-};
-
-
-template< class T >
-inline void RangeCheck( const T &value, int minValue, int maxValue )
-{
-#ifdef _DEBUG
- extern bool g_bDoRangeChecks;
- if ( ThreadInMainThread() && g_bDoRangeChecks )
- {
- // Ignore the min/max stuff for now.. just make sure it's not a NAN.
- Assert( _finite( value ) );
- }
-#endif
-}
-
-inline void RangeCheck( const Vector &value, int minValue, int maxValue )
-{
-#ifdef _DEBUG
- RangeCheck( value.x, minValue, maxValue );
- RangeCheck( value.y, minValue, maxValue );
- RangeCheck( value.z, minValue, maxValue );
-#endif
-}
-
-
-template< class T, int minValue, int maxValue, int startValue >
-class CRangeCheckedVar
-{
-public:
-
- inline CRangeCheckedVar()
- {
- m_Val = startValue;
- }
-
- inline CRangeCheckedVar( const T &value )
- {
- *this = value;
- }
-
- T GetRaw() const
- {
- return m_Val;
- }
-
- // Clamp the value to its limits. Interpolation code uses this after interpolating.
- inline void Clamp()
- {
- if ( m_Val < minValue )
- m_Val = minValue;
- else if ( m_Val > maxValue )
- m_Val = maxValue;
- }
-
- inline operator const T&() const
- {
- return m_Val;
- }
-
- inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator=( const T &value )
- {
- RangeCheck( value, minValue, maxValue );
- m_Val = value;
- return *this;
- }
-
- inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator+=( const T &value )
- {
- return (*this = m_Val + value);
- }
-
- inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator-=( const T &value )
- {
- return (*this = m_Val - value);
- }
-
- inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator*=( const T &value )
- {
- return (*this = m_Val * value);
- }
-
- inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator/=( const T &value )
- {
- return (*this = m_Val / value);
- }
-
-private:
-
- T m_Val;
-};
-
-#endif // RANGECHECKEDVAR_H
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#ifndef RANGECHECKEDVAR_H +#define RANGECHECKEDVAR_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "tier0/dbg.h" +#include "tier0/threadtools.h" +#include "mathlib/vector.h" +#include <float.h> + + +// Use this to disable range checks within a scope. +class CDisableRangeChecks +{ +public: + CDisableRangeChecks(); + ~CDisableRangeChecks(); +}; + + +template< class T > +inline void RangeCheck( const T &value, int minValue, int maxValue ) +{ +#ifdef _DEBUG + extern bool g_bDoRangeChecks; + if ( ThreadInMainThread() && g_bDoRangeChecks ) + { + // Ignore the min/max stuff for now.. just make sure it's not a NAN. + Assert( _finite( value ) ); + } +#endif +} + +inline void RangeCheck( const Vector &value, int minValue, int maxValue ) +{ +#ifdef _DEBUG + RangeCheck( value.x, minValue, maxValue ); + RangeCheck( value.y, minValue, maxValue ); + RangeCheck( value.z, minValue, maxValue ); +#endif +} + + +template< class T, int minValue, int maxValue, int startValue > +class CRangeCheckedVar +{ +public: + + inline CRangeCheckedVar() + { + m_Val = startValue; + } + + inline CRangeCheckedVar( const T &value ) + { + *this = value; + } + + T GetRaw() const + { + return m_Val; + } + + // Clamp the value to its limits. Interpolation code uses this after interpolating. + inline void Clamp() + { + if ( m_Val < minValue ) + m_Val = minValue; + else if ( m_Val > maxValue ) + m_Val = maxValue; + } + + inline operator const T&() const + { + return m_Val; + } + + inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator=( const T &value ) + { + RangeCheck( value, minValue, maxValue ); + m_Val = value; + return *this; + } + + inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator+=( const T &value ) + { + return (*this = m_Val + value); + } + + inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator-=( const T &value ) + { + return (*this = m_Val - value); + } + + inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator*=( const T &value ) + { + return (*this = m_Val * value); + } + + inline CRangeCheckedVar<T, minValue, maxValue, startValue>& operator/=( const T &value ) + { + return (*this = m_Val / value); + } + +private: + + T m_Val; +}; + +#endif // RANGECHECKEDVAR_H |