Skip to content

Commit

Permalink
Multiple changes
Browse files Browse the repository at this point in the history
- Changed the return value of ObjGenDelOps::IsA.
- Added Object::HasInstance.
- Added the operator ~ to Boolean.
- Updated the quickbook docs.
- Other minor changes.
  • Loading branch information
matus-chochlik committed Feb 5, 2015
1 parent d39240d commit 60904dc
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 64 deletions.
4 changes: 2 additions & 2 deletions doc/quickbook/oalplus/quickref/object/optional.qbk
@@ -1,4 +1,4 @@
[/ Copyright 2014-2015 Matus Chochlik. Distributed under the Boost ]
[/ Copyright 2014-2015 Matus Chochlik. Distributed under the Boost ]
[/ Software License, Version 1.0. (See accompanying file ]
[/ LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ]

Expand All @@ -13,7 +13,7 @@ objects] and in contrast to [^__Object] it [*does] allow to construct uninitiali
instances which can be initialized later.

An [^Optional<__Object>] can be used everywhere an [^__Object] could be
used, but it must be initialized (the [^IsInitialized()] member function
used, but it must be initialized (the [^HasValidName()] member function
must return true), otherwise usage results in undefined behavior.

[import optional.hpp]
Expand Down
10 changes: 5 additions & 5 deletions doc/quickbook/oglplus/quickref/object/optional.hpp
@@ -1,5 +1,5 @@
/*
* Copyright 2014 Matus Chochlik. Distributed under the Boost
* Copyright 2014-2015 Matus Chochlik. Distributed under the Boost
* Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
Expand Down Expand Up @@ -33,12 +33,12 @@ class Optional
>*/

explicit operator bool (void) const; /*<
Equivalent to [^IsInitialized].
Equivalent to [^HasValidName].
>*/
bool IsInitialized(void) const noexcept; /*<
Returns true if the object is initialized, false otherwise.
bool HasValidName(void) const noexcept; /*<
Returns true if the object has a valid name, false otherwise.
The only things that can safely be done with
an uninitialized [^Optional<__Object>] is assignment,
an invalid name [^Optional<__Object>] is assignment,
moving, destruction and checking whether it is
initialized. On the other hand initialized
[^Optional<__Object>] can be used everywhere where
Expand Down
4 changes: 2 additions & 2 deletions doc/quickbook/oglplus/quickref/object/optional.qbk
@@ -1,4 +1,4 @@
[/ Copyright 2014 Matus Chochlik. Distributed under the Boost ]
[/ Copyright 2014-2015 Matus Chochlik. Distributed under the Boost ]
[/ Software License, Version 1.0. (See accompanying file ]
[/ LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ]

Expand All @@ -13,7 +13,7 @@ objects] and in contrast to [^__Object] it [*does] allow to construct uninitiali
instances which can be initialized later.

An [^Optional<__Object>] can be used everywhere an [^__Object] could be
used, but it must be initialized (the [^IsInitialized()] member function
used, but it must be initialized (the [^HasValidName()] member function
must return true), otherwise usage results in undefined behavior.

[import optional.hpp]
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/buffer.hpp
Expand Up @@ -68,10 +68,12 @@ class ObjGenDelOps<tag::Buffer>
OGLPLUS_VERIFY_SIMPLE(DeleteBuffers);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsBuffer)(name);
Boolean result(
OGLPLUS_GLFUNC(IsBuffer)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsBuffer);
return result;
}
Expand Down
44 changes: 44 additions & 0 deletions include/oglplus/detail/boolean.hpp
Expand Up @@ -19,10 +19,43 @@

namespace oglplus {

template <typename T, T TrueVal, T FalseVal>
struct BoolImpl;

template <typename T, T TrueVal, T FalseVal>
struct WeakBoolImpl
{
private:
T _v;

explicit
WeakBoolImpl(T v)
: _v(v)
{ }

friend struct BoolImpl<T, TrueVal, FalseVal>;
public:
operator bool (void) const
OGLPLUS_NOEXCEPT(true)
{
return _v != FalseVal;
}

bool operator ! (void) const
OGLPLUS_NOEXCEPT(true)
{
return _v != TrueVal;
}
};

template <typename T, T TrueVal, T FalseVal>
struct BoolImpl
{
private:
static_assert(TrueVal != FalseVal, "");
static_assert(TrueVal >= 0, "");
static_assert(FalseVal>= 0, "");

T _v;
public:
// implementation detail
Expand Down Expand Up @@ -68,6 +101,12 @@ struct BoolImpl
}
}

static
BoolImpl Indeterminate(void)
{
return BoolImpl(TrueVal+FalseVal+1);
}

operator bool (void) const
OGLPLUS_NOEXCEPT(true)
{
Expand All @@ -79,6 +118,11 @@ struct BoolImpl
{
return _v == FalseVal;
}

WeakBoolImpl<T, TrueVal, FalseVal> operator ~ (void) const
{
return WeakBoolImpl<T, TrueVal, FalseVal>(_v);
}
};

} // namespace oglplus
Expand Down
5 changes: 2 additions & 3 deletions include/oglplus/ext/AMD_performance_monitor.hpp
Expand Up @@ -304,10 +304,9 @@ class ObjGenDelOps<tag::PerfMonitorAMD>
OGLPLUS_VERIFY_SIMPLE(DeleteSamplers);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint /*name*/)
{
assert(name != 0);
return GL_TRUE;
return Boolean::Indeterminate();
}
};

Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/ext/NV_path_rendering/path.hpp
Expand Up @@ -65,10 +65,12 @@ class ObjGenDelOps<tag::PathNV>
OGLPLUS_VERIFY_SIMPLE(DeletePathsNV);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsPathNV)(name);
Boolean result(
OGLPLUS_GLFUNC(IsPathNV)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsPathNV);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/framebuffer.hpp
Expand Up @@ -65,10 +65,12 @@ class ObjGenDelOps<tag::Framebuffer>
OGLPLUS_VERIFY_SIMPLE(DeleteFramebuffers);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsFramebuffer)(name);
Boolean result(
OGLPLUS_GLFUNC(IsFramebuffer)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsFramebuffer);
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions include/oglplus/object/name_tpl.hpp
Expand Up @@ -146,8 +146,8 @@ class ObjectName
return *this;
}

/// Returns true if the object name is initialized, false otherwise
bool IsInitialized(void) const
/// Returns true if the object name is valid, false otherwise
bool HasValidName(void) const
OGLPLUS_NOEXCEPT(true)
{
return this->_name != _invalid_name();
Expand Down
8 changes: 4 additions & 4 deletions include/oglplus/object/optional.hpp
Expand Up @@ -24,7 +24,7 @@ namespace oglplus {
* instances which can be initialized later.
*
* An Optional<Object> can be used everywhere an Object could be
* used, but it must be initialized (the IsInitialized() member function
* used, but it must be initialized (the HasValidName() member function
* must return true), otherwise usage results in undefined behavior.
*
* @ingroup modifier_classes
Expand All @@ -40,7 +40,7 @@ class OptionalImpl<tag::Object, Object>
* moving, destruction and checking whether it is
* initialized.
*
* @see IsInitialized
* @see HasValidName
* @see Assign
*/
OptionalImpl(void)
Expand All @@ -53,7 +53,7 @@ class OptionalImpl<tag::Object, Object>
* a plain Object could be used, furthermore Optional<Object>
* can also be cleared (this brings it in uninitialized state)
*
* @see IsInitialized
* @see HasValidName
* @see Clear
*/
OptionalImpl(Object&& temp)
Expand All @@ -77,7 +77,7 @@ class OptionalImpl<tag::Object, Object>
operator bool (void) const
OGLPLUS_NOEXCEPT(true)
{
return this->IsInitialized();
return this->HasValidName();
}

/// Releases the stored object and makes this Optional uninitialized
Expand Down
7 changes: 7 additions & 0 deletions include/oglplus/object/wrap_tpl.hpp
Expand Up @@ -332,6 +332,13 @@ class ObjectTpl
return *this;
}

static
auto HasInstance(ObjectName<ObjTag> name) ->
decltype(ObjGenDelOps<ObjTag>::IsA(GetName(name))) // TODO
{
return ObjGenDelOps<ObjTag>::IsA(GetName(name));
}

/// Returns the textual description of this object
const std::string& Description(void) const
{
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/program.hpp
Expand Up @@ -68,10 +68,12 @@ class ObjGenDelOps<tag::Program>
}
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsProgram)(name);
Boolean result(
OGLPLUS_GLFUNC(IsProgram)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsProgram);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/program_pipeline.hpp
Expand Up @@ -64,10 +64,12 @@ class ObjGenDelOps<tag::ProgramPipeline>
OGLPLUS_VERIFY_SIMPLE(DeleteProgramPipelines);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsProgramPipeline)(name);
Boolean result(
OGLPLUS_GLFUNC(IsProgramPipeline)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsProgramPipeline);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/query.hpp
Expand Up @@ -70,10 +70,12 @@ class ObjGenDelOps<tag::Query>
OGLPLUS_VERIFY_SIMPLE(DeleteQueries);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsQuery)(name);
Boolean result(
OGLPLUS_GLFUNC(IsQuery)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsQuery);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/renderbuffer.hpp
Expand Up @@ -57,10 +57,12 @@ class ObjGenDelOps<tag::Renderbuffer>
OGLPLUS_VERIFY_SIMPLE(DeleteRenderbuffers);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsRenderbuffer)(name);
Boolean result(
OGLPLUS_GLFUNC(IsRenderbuffer)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsRenderbuffer);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/sampler.hpp
Expand Up @@ -67,10 +67,12 @@ class ObjGenDelOps<tag::Sampler>
OGLPLUS_VERIFY_SIMPLE(DeleteSamplers);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsSampler)(name);
Boolean result(
OGLPLUS_GLFUNC(IsSampler)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsSampler);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/shader.hpp
Expand Up @@ -67,10 +67,12 @@ class ObjGenDelOps<tag::Shader>
}
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsShader)(name);
Boolean result(
OGLPLUS_GLFUNC(IsShader)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsShader);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/texture.hpp
Expand Up @@ -86,10 +86,12 @@ class ObjGenDelOps<tag::Texture>
OGLPLUS_VERIFY_SIMPLE(DeleteTextures);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsTexture)(name);
Boolean result(
OGLPLUS_GLFUNC(IsTexture)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsTexture);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions include/oglplus/transform_feedback.hpp
Expand Up @@ -60,10 +60,12 @@ class ObjGenDelOps<tag::TransformFeedback>
OGLPLUS_VERIFY_SIMPLE(DeleteTransformFeedbacks);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsTransformFeedback)(name);
Boolean result(
OGLPLUS_GLFUNC(IsTransformFeedback)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsTransformFeedback);
return result;
}
Expand Down
9 changes: 6 additions & 3 deletions include/oglplus/vertex_array.hpp
Expand Up @@ -16,6 +16,7 @@
#include <oglplus/glfunc.hpp>
#include <oglplus/object/wrapper.hpp>
#include <oglplus/error/object.hpp>
#include <oglplus/boolean.hpp>
#include <cassert>

namespace oglplus {
Expand Down Expand Up @@ -54,10 +55,12 @@ class ObjGenDelOps<tag::VertexArray>
OGLPLUS_VERIFY_SIMPLE(DeleteVertexArrays);
}

static GLboolean IsA(GLuint name)
static Boolean IsA(GLuint name)
{
assert(name != 0);
GLboolean result = OGLPLUS_GLFUNC(IsVertexArray)(name);
Boolean result(
OGLPLUS_GLFUNC(IsVertexArray)(name),
std::nothrow
);
OGLPLUS_VERIFY_SIMPLE(IsVertexArray);
return result;
}
Expand Down

0 comments on commit 60904dc

Please sign in to comment.