PrevUpHomeNext

Boolean

oglplus/boolean.hpp

OGLplus defines a wrapper for boolean values represented in OpenGL, OpenAL, etc. by integer types with wider than one-bit range.

Instances of this type are implicitly constructible from and convertible to bool values and also explicitly constructible from values of the underlying type (like GLint, ALint, EGLBoolean, etc.) Instances of Boolean can be in three states: true, false and indeterminate, (i.e. both the operator bool and operator ! can return false for some instances).

Implementation

template <typename B, typename T, T TrueValue, T FalseValue>
struct WeakBoolImpl
{
public:
	operator bool (void) const
	noexcept; 1

	bool operator ! (void) const;
	noexcept; 2
};

template <typename B, typename T, T TrueValue, T FalseValue>
struct BoolImpl
{
public:
	BoolImpl(void)
	noexcept; 3

	BoolImpl(bool bool_value)
	noexcept;

	BoolImpl(T value, std::nothrow_t);
	noexcept; 4

	explicit
	BoolImpl(T value); 5

	operator bool (void) const
	noexcept; 6

	bool operator ! (void) const;
	noexcept; 7

	WeakBoolImpl<T, TrueValue, FalseValue>
	operator ~ (void) const
	noexcept;
};

1

Returns true if the wrapped value is not equal to FalseValue.

2

Returns true if the wrapped value is not equal to TrueValue.

3

Creates a false boolean value.

4

Constructs a boolean from a value in the underlying type. This version does not throw if the value is neither TrueValue nor FalseValue, in such case the constructed instance is indeterminate.

5

Constructs a boolean from a value in the underlying type. This constructor throws a std::domain_error if value is neither TrueValue not FalseValue.

6

Returns true if the wrapped value is equal to TrueValue.

7

Returns true if the wrapped value is equal to FalseValue.

Definition

typedef BoolImpl<GLboolean, GLint, GL_TRUE, GL_FALSE> Boolean;

Examples

Context gl;

if(gl.IsEnabled(Capability::DepthTest)) 1
{
	/* ... */
}

if(!gl.IsEnabled(Capability::StencilTest)) 2
{
	/* ... */
}

if(~gl.IsEnabled(Capability::DepthTest)) 3
{
	/* ... */
}

if(!~gl.IsEnabled(Capability::StencilTest)) 4
{
	/* ... */
}

1

Equal to GL_TRUE.

2

Equal to GL_FALSE.

3

Not equal to GL_FALSE.

4

Not equal to GL_TRUE.


PrevUpHomeNext