BoundsChecking
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BOUNDSCHECKING
#define OSG_BOUNDSCHECKING 1
#include <osg/Notify>
namespace osg {
template <typename T>
inline void clampGEQUAL(T& value,const T minValue,const char* valueName)
{
if (value<minValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is below permitted minimum, clamping to "<<minValue<<"."<< std::endl;
value = minValue;
}
}
template <typename T>
inline void clampLEQUAL(T& value,const T maxValue,const char* valueName)
{
if (value>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is above permitted maximum, clamping to "<<maxValue<<"."<< std::endl;
value = maxValue;
}
}
template <typename T>
inline void clampBetweenRange(T& value,const T minValue,const T maxValue,const char* valueName)
{
if (value<minValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is below permitted minimum, clamping to "<<minValue<<"."<< std::endl;
value = minValue;
}
else
if (value>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is above permitted maximum, clamping to "<<maxValue<<"."<< std::endl;
value = maxValue;
}
}
template <typename A, typename T>
inline void clampArrayElementGEQUAL(A& value,unsigned int i,const T minValue,const char* valueName)
{
if (value[i]<minValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is below permitted minimum, clamping to "<<minValue<<"."<< std::endl;
value[i] = minValue;
}
}
template <typename A, typename T>
inline void clampArrayElementLEQUAL(A& value,unsigned int i,const T maxValue,const char* valueName)
{
if (value[i]>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is above permitted maximum, clamping to "<<maxValue<<"."<< std::endl;
value = maxValue;
}
}
template <typename A, typename T>
inline void clampArrayElementBetweenRange(A& value,unsigned int i,const T minValue,const T maxValue,const char* valueName)
{
if (value[i]<minValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is below permitted minimum, clamping to "<<minValue<<"."<< std::endl;
value[i] = minValue;
}
else
if (value[i]>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is above permitted maximum, clamping to "<<maxValue<<"."<< std::endl;
value[i] = maxValue;
}
}
template <typename A, typename T>
inline void clampArrayElementsGEQUAL(A& value,unsigned int first,unsigned int last,const T minValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementGEQUAL(value,i,minValue,valueName);
}
template <typename A, typename T>
inline void clampArrayElementsLEQUAL(A& value,unsigned int first,unsigned int last,const T maxValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementLEQUAL(value,i,maxValue,valueName);
}
template <typename A, typename T>
inline void clampArrayElementsBetweenRange(A& value,unsigned int first,unsigned int last,const T minValue,const T maxValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementBetweenRange(value,i,minValue,maxValue,valueName);
}
template <typename A, typename T>
inline void clampArray3GEQUAL(A& value,const T minValue,const char* valueName)
{
clampArrayElementsGEQUAL(value,0u,2u,minValue,valueName);
}
template <typename A, typename T>
inline void clampArray3LEQUAL(A& value,const T maxValue,const char* valueName)
{
clampArrayElementsLEQUAL(value,0u,2u,maxValue,valueName);
}
template <typename A, typename T>
inline void clampArray3BetweenRange(A& value,const T minValue,const T maxValue,const char* valueName)
{
clampArrayElementsBetweenRange(value,0u,2u,minValue,maxValue,valueName);
}
template <typename A, typename T>
inline void clampArray4GEQUAL(A& value,const T minValue,const char* valueName)
{
clampArrayElementsGEQUAL(value,0u,3u,minValue,valueName);
}
template <typename A, typename T>
inline void clampArray4LEQUAL(A& value,const T maxValue,const char* valueName)
{
clampArrayElementsLEQUAL(value,0u,3u,maxValue,valueName);
}
template <typename A, typename T>
inline void clampArray4BetweenRange(A& value,const T minValue,const T maxValue,const char* valueName)
{
clampArrayElementsBetweenRange(value,0u,3u,minValue,maxValue,valueName);
}
}
#endif
Notify
osg
Definition AlphaFunc:19
osg::clampArrayElementGEQUAL
void clampArrayElementGEQUAL(A &value, unsigned int i, const T minValue, const char *valueName)
Definition BoundsChecking:74
osg::clampArray4GEQUAL
void clampArray4GEQUAL(A &value, const T minValue, const char *valueName)
Definition BoundsChecking:188
osg::WARN
@ WARN
Definition Notify:33
osg::clampArray3GEQUAL
void clampArray3GEQUAL(A &value, const T minValue, const char *valueName)
Definition BoundsChecking:156
osg::clampArrayElementBetweenRange
void clampArrayElementBetweenRange(A &value, unsigned int i, const T minValue, const T maxValue, const char *valueName)
Definition BoundsChecking:102
osg::clampArrayElementsBetweenRange
void clampArrayElementsBetweenRange(A &value, unsigned int first, unsigned int last, const T minValue, const T maxValue, const char *valueName)
Definition BoundsChecking:145
osg::clampArray3BetweenRange
void clampArray3BetweenRange(A &value, const T minValue, const T maxValue, const char *valueName)
Definition BoundsChecking:177
osg::clampArray3LEQUAL
void clampArray3LEQUAL(A &value, const T maxValue, const char *valueName)
Definition BoundsChecking:165
osg::clampArrayElementsLEQUAL
void clampArrayElementsLEQUAL(A &value, unsigned int first, unsigned int last, const T maxValue, const char *valueName)
Definition BoundsChecking:132
osg::clampArrayElementsGEQUAL
void clampArrayElementsGEQUAL(A &value, unsigned int first, unsigned int last, const T minValue, const char *valueName)
Definition BoundsChecking:122
osg::clampArray4LEQUAL
void clampArray4LEQUAL(A &value, const T maxValue, const char *valueName)
Definition BoundsChecking:197
osg::clampBetweenRange
void clampBetweenRange(T &value, const T minValue, const T maxValue, const char *valueName)
Definition BoundsChecking:54
osg::clampArrayElementLEQUAL
void clampArrayElementLEQUAL(A &value, unsigned int i, const T maxValue, const char *valueName)
Definition BoundsChecking:87
osg::notify
std::ostream & notify(void)
Definition Notify:80
osg::clampGEQUAL
void clampGEQUAL(T &value, const T minValue, const char *valueName)
Definition BoundsChecking:26
osg::clampArray4BetweenRange
void clampArray4BetweenRange(A &value, const T minValue, const T maxValue, const char *valueName)
Definition BoundsChecking:209
osg::clampLEQUAL
void clampLEQUAL(T &value, const T maxValue, const char *valueName)
Definition BoundsChecking:39