MGIS
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, ...)   ::mgis::construct<Type>(e, __VA_ARGS__)
 a simple wrapper around the construct function which handles the declaration of the source location if needed
 
#define MGIS_MAKE_UNIQUE(Type, e, ...)   ::mgis::make_unique<Type>(e, __VA_ARGS__)
 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, ...)    ::mgis::make_unique_as<BaseType, Type>(e, __VA_ARGS__)
 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, ...)    ::mgis::make_shared_as<BaseType, Type>(e, __VA_ARGS__)
 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, ...)   ::mgis::make_shared<Type>(e, __VA_ARGS__)
 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 std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>
std::optional< Type > mgis::construct (Context &, ArgumentsTypes &&...) noexcept
 try to build an object of the given type.
 
template<typename Type , typename... ArgumentsTypes>
requires std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>
std::unique_ptr< Type > mgis::make_unique (Context &, ArgumentsTypes &&...) 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> && std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>
std::unique_ptr< BaseType > mgis::make_unique_as (Context &, ArgumentsTypes &&...) noexcept
 try to build a unique pointer of a base type holding the given type.
 
template<typename Type , typename... ArgumentsTypes>
requires std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>
std::shared_ptr< Type > mgis::make_shared (Context &, ArgumentsTypes &&...) 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> && std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>
std::shared_ptr< BaseType > mgis::make_shared_as (Context &, ArgumentsTypes &&...) noexcept
 try to build a shared pointer of a base type holding the given type.
 

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,
  ... 
)    ::mgis::construct<Type>(e, __VA_ARGS__)

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,
  ... 
)    ::mgis::make_shared<Type>(e, __VA_ARGS__)

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,
  ... 
)     ::mgis::make_shared_as<BaseType, Type>(e, __VA_ARGS__)

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,
  ... 
)    ::mgis::make_unique<Type>(e, __VA_ARGS__)

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,
  ... 
)     ::mgis::make_unique_as<BaseType, Type>(e, __VA_ARGS__)

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 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 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 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 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 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