MGIS 3.1.0
Loading...
Searching...
No Matches
Construct.hxx File Reference

This header declares utility functions to build objects handling any exception thrown by a constructor. More...

#include <memory>
#include <optional>
#include <type_traits>
#include "MGIS/Context.hxx"
#include "MGIS/InvalidResult.hxx"
#include "MGIS/Utilities/Construct.ixx"

Namespaces

namespace  mgis
 the namespace mgis encloses all the MGIS project.

Macros

#define MGIS_CONSTRUCT(Type, e, ...)
 a simple wrapper around the construct function which handles the declaration of the source location if needed
#define MGIS_MAKE_UNIQUE(Type, e, ...)
 a simple wrapper around the make_unique function which handles the declaration of the source location if needed.
#define MGIS_MAKE_UNIQUE_AS(BaseType, Type, e, ...)
 a simple wrapper around the make_unique_as function which handles the declaration of the source location if needed
#define MGIS_MAKE_SHARED_AS(BaseType, Type, e, ...)
 a simple wrapper around the make_shared_as function which handles the declaration of the source location if needed.
#define MGIS_MAKE_SHARED(Type, e, ...)
 a simple wrapper around the make_shared function which handles the declaration of the source location if needed
#define MGIS_TRY_CONSTRUCT(Type, v, e, ...)
 an helper macro to build a variable the constructor of which may throw
#define MGIS_TRY_MAKE_UNIQUE(Type, v, e, ...)
 an helper macro to build an unique pointer for type the constructor of which may throw
#define MGIS_TRY_MAKE_UNIQUE_AS(BaseType, Type, v, e, ...)
 an helper macro to build an unique pointer for type the constructor of which may throw
#define MGIS_TRY_MAKE_SHARED(Type, v, e, ...)
 an helper macro to build an shared pointer for type the constructor of which may throw
#define MGIS_TRY_MAKE_SHARED_AS(BaseType, Type, v, e, ...)
 an helper macro to build an shared pointer for type the constructor of which may throw

Functions

template<typename Type, typename... ArgumentsTypes>
requires ::mgis::internals::is_constructible<Type, ArgumentsTypes...>
std::optional< Type > mgis::construct (Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
 try to build an object of the given type.
template<typename Type, typename... ArgumentsTypes>
requires ::mgis::internals::is_constructible<Type, ArgumentsTypes...>
std::unique_ptr< Type > mgis::make_unique (Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
 try to build a unique pointer holding the given type.
template<typename BaseType, typename Type, typename... ArgumentsTypes>
requires std::is_base_of_v<BaseType, Type> && ::mgis::internals::is_constructible<Type, ArgumentsTypes...>
std::unique_ptr< BaseType > mgis::make_unique_as (Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
 try to build a unique pointer of a base type holding the given type.
template<typename Type, typename... ArgumentsTypes>
requires ::mgis::internals::is_constructible<Type, ArgumentsTypes...>
std::shared_ptr< Type > mgis::make_shared (Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
 try to build a shared pointer holding the given type.
template<typename BaseType, typename Type, typename... ArgumentsTypes>
requires std::is_base_of_v<BaseType, Type> && ::mgis::internals::is_constructible<Type, ArgumentsTypes...>
std::shared_ptr< BaseType > mgis::make_shared_as (Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
 try to build a shared pointer of a base type holding the given type.

Variables

template<typename Type, typename... ArgumentsTypes>
constexpr auto mgis::internals::is_constructible_without_context
template<typename Type, typename... ArgumentsTypes>
constexpr auto mgis::internals::is_constructible_with_context
template<typename Type, typename... ArgumentsTypes>
constexpr auto mgis::internals::is_constructible

Detailed Description

This header declares utility functions to build objects handling any exception thrown by a constructor.

Date
06/11/2022

Macro Definition Documentation

◆ MGIS_CONSTRUCT

#define MGIS_CONSTRUCT ( Type,
e,
... )
Value:
::mgis::construct<Type>(e, __VA_ARGS__)
std::optional< Type > construct(Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
try to build an object of the given type.

a simple wrapper around the construct function which handles the declaration of the source location if needed

Parameters
[in]Typetype of the object built
[in,out]ctxexecution context

◆ MGIS_MAKE_SHARED

#define MGIS_MAKE_SHARED ( Type,
e,
... )
Value:
std::shared_ptr< Type > make_shared(Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
try to build a shared pointer holding the given type.

a simple wrapper around the make_shared function which handles the declaration of the source location if needed

Parameters
[in]Typetype of the object built
[in,out]ctxexecution context

◆ MGIS_MAKE_SHARED_AS

#define MGIS_MAKE_SHARED_AS ( BaseType,
Type,
e,
... )
Value:
std::shared_ptr< BaseType > make_shared_as(Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
try to build a shared pointer of a base type holding the given type.

a simple wrapper around the make_shared_as function which handles the declaration of the source location if needed.

Parameters
[in]Typetype of the object built
[in,out]ctxexecution context

◆ MGIS_MAKE_UNIQUE

#define MGIS_MAKE_UNIQUE ( Type,
e,
... )
Value:
std::unique_ptr< Type > make_unique(Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
try to build a unique pointer holding the given type.

a simple wrapper around the make_unique function which handles the declaration of the source location if needed.

Parameters
[in]Typetype of the object built
[in,out]ctxexecution context

◆ MGIS_MAKE_UNIQUE_AS

#define MGIS_MAKE_UNIQUE_AS ( BaseType,
Type,
e,
... )
Value:
std::unique_ptr< BaseType > make_unique_as(Context &, ArgumentsTypes &&...) MGIS_NOEXCEPT
try to build a unique pointer of a base type holding the given type.

a simple wrapper around the make_unique_as function which handles the declaration of the source location if needed

Parameters
[in]Typetype of the object built
[in,out]ctxexecution context

◆ MGIS_TRY_CONSTRUCT

#define MGIS_TRY_CONSTRUCT ( Type,
v,
e,
... )
Value:
std::optional<Type> MGIS_TEMPORARY_VARIABLE(v) = \
MGIS_CONSTRUCT(Type, e, __VA_ARGS__); \
if (!MGIS_TEMPORARY_VARIABLE(v).has_value()) { \
return ::mgis::InvalidResult{}; \
} \
Type& v = *(MGIS_TEMPORARY_VARIABLE(v))

an helper macro to build a variable the constructor of which may throw

Parameters
[in]Typetype of the object built
[in]vname of the variable built
[in,out]ctxexecution context

◆ MGIS_TRY_MAKE_SHARED

#define MGIS_TRY_MAKE_SHARED ( Type,
v,
e,
... )
Value:
std::shared_ptr<Type> v = MGIS_MAKE_SHARED(Type, e, __VA_ARGS__); \
if (v.get() == nullptr) { \
return ::mgis::InvalidResult{}; \
} \
static_cast<void>(0)
#define MGIS_MAKE_SHARED(Type, e,...)
a simple wrapper around the make_shared function which handles the declaration of the source location...
Definition Construct.hxx:92

an helper macro to build an shared pointer for type the constructor of which may throw

Parameters
[in]Typetype of the object built
[in]vname of the variable built
[in,out]ctxexecution context

◆ MGIS_TRY_MAKE_SHARED_AS

#define MGIS_TRY_MAKE_SHARED_AS ( BaseType,
Type,
v,
e,
... )
Value:
std::shared_ptr<BaseType> v = \
MGIS_MAKE_SHARED_AS(BaseType, Type, e, __VA_ARGS__); \
if (v.get() == nullptr) { \
return ::mgis::InvalidResult{}; \
} \
static_cast<void>(0)

an helper macro to build an shared pointer for type the constructor of which may throw

Parameters
[in]BaseTypepointer to a base type
[in]Typetype of the object built
[in]vname of the variable built
[in,out]ctxexecution context

◆ MGIS_TRY_MAKE_UNIQUE

#define MGIS_TRY_MAKE_UNIQUE ( Type,
v,
e,
... )
Value:
std::unique_ptr<Type> v = MGIS_MAKE_UNIQUE(Type, e, __VA_ARGS__); \
if (v.get() == nullptr) { \
return ::mgis::InvalidResult{}; \
} \
static_cast<void>(0)
#define MGIS_MAKE_UNIQUE(Type, e,...)
a simple wrapper around the make_unique function which handles the declaration of the source location...
Definition Construct.hxx:43

an helper macro to build an unique pointer for type the constructor of which may throw

Parameters
[in]Typetype of the object built
[in]vname of the variable built
[in,out]ctxexecution context

◆ MGIS_TRY_MAKE_UNIQUE_AS

#define MGIS_TRY_MAKE_UNIQUE_AS ( BaseType,
Type,
v,
e,
... )
Value:
std::unique_ptr<BaseType> v = \
MGIS_MAKE_UNIQUE_AS(BaseType, Type, e, __VA_ARGS__); \
if (v.get() == nullptr) { \
return ::mgis::InvalidResult{}; \
} \
static_cast<void>(0)

an helper macro to build an unique pointer for type the constructor of which may throw

Parameters
[in]BaseTypepointer to a base type
[in]Typetype of the object built
[in]vname of the variable built
[in,out]ctxexecution context

Variable Documentation

◆ is_constructible

template<typename Type, typename... ArgumentsTypes>
auto mgis::internals::is_constructible
inlineconstexpr
Initial value:
=
is_constructible_without_context<Type, ArgumentsTypes...> ||
is_constructible_with_context<Type, ArgumentsTypes...>

◆ is_constructible_with_context

template<typename Type, typename... ArgumentsTypes>
auto mgis::internals::is_constructible_with_context
inlineconstexpr
Initial value:
=
std::is_constructible_v<std::remove_const_t<Type>,
ArgumentsTypes...>
a class used to pass an execution context to most methods of MGIS and gather information (error,...
Definition Context.hxx:47

◆ is_constructible_without_context

template<typename Type, typename... ArgumentsTypes>
auto mgis::internals::is_constructible_without_context
inlineconstexpr
Initial value:
=
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>