BioDynaMo  v1.05.119-a4ff3934
type.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_UTIL_TYPE_H_
16 #define CORE_UTIL_TYPE_H_
17 
18 #include <type_traits>
19 #include <typeinfo>
20 
22 #include "core/shape.h"
23 #include "core/util/string.h"
24 
25 namespace bdm {
26 
29 template <bool Condition, typename T, typename U>
30 struct type_ternary_operator {}; // NOLINT
31 
32 template <typename T, typename U>
33 struct type_ternary_operator<true, T, U> {
34  typedef T type; // NOLINT
35 };
36 
37 template <typename T, typename U>
38 struct type_ternary_operator<false, T, U> {
39  typedef U type; // NOLINT
40 };
41 
43 template <typename T>
44 using raw_type = std::remove_pointer_t<std::decay_t<T>>; // NOLINT
45 
46 // ----------------------------------------------------------------------------
48 template <typename T>
49 struct IsArray : std::false_type {};
50 
51 template <typename T, size_t N>
52 struct IsArray<std::array<T, N>> : std::true_type {};
53 
54 template <typename T, std::size_t N>
55 struct IsArray<MathArray<T, N>> : std::true_type {};
56 
59 template <typename TTo, typename TFrom>
60 TTo bdm_static_cast(TFrom from) { // NOLINT
61  assert(dynamic_cast<TTo>(from) &&
62  Concat("Could not cast object ", from, " to type ", typeid(TTo).name())
63  .c_str());
64  return static_cast<TTo>(from);
65 }
66 
67 } // namespace bdm
68 
69 #endif // CORE_UTIL_TYPE_H_
shape.h
bdm
Definition: agent.cc:39
string.h
bdm::raw_type
std::remove_pointer_t< std::decay_t< T > > raw_type
Type trait that converts T*, T&, T&&, T*& to T
Definition: type.h:44
bdm::type_ternary_operator< true, T, U >::type
T type
Definition: type.h:34
bdm::type_ternary_operator< false, T, U >::type
U type
Definition: type.h:39
bdm::type_ternary_operator
Definition: type.h:30
math_array.h
bdm::Concat
std::string Concat(const Args &... parts)
Concatenates all arguments into a string. Equivalent to streaming all arguments into a stringstream a...
Definition: string.h:70
bdm::bdm_static_cast
TTo bdm_static_cast(TFrom from)
Definition: type.h:60
std
Definition: agent_uid.h:117
bdm::MathArray
Definition: math_array.h:36
bdm::IsArray
Checks whether T is std::array or bdm::MathArray.
Definition: type.h:49