GEOS
DefaultValue.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_DATAREPOSITORY_DEFAULTVALUE_HPP_
21 #define GEOS_DATAREPOSITORY_DEFAULTVALUE_HPP_
22 
23 // Source includes
24 #include "common/DataTypes.hpp"
25 #include "codingUtilities/traits.hpp"
26 
27 namespace geos
28 {
29 namespace dataRepository
30 {
31 namespace internal
32 {
33 
39 template< typename T >
40 struct is_defaultable
41 {
43  static constexpr bool value = std::is_arithmetic< T > ::value ||
44  std::is_same< T, string >::value ||
45  std::is_same< T, Path >::value ||
46  traits::is_tensorT< T > ||
47  std::is_enum< T >::value;
48 };
49 
57 template< typename T, typename ENABLE=void >
58 struct Helper
59 {
61  static constexpr bool has_default_value = false;
62 
64  using value_type = void;
65 };
66 
75 template< typename T >
76 struct Helper< T, std::enable_if_t< is_defaultable< T >::value > >
77 {
79  static constexpr bool has_default_value = true;
80 
82  using value_type = T;
83 
85  value_type value = value_type();
86 };
87 
97 template< typename T >
98 struct Helper< T, std::enable_if_t< traits::HasAlias_value_type< T > &&
99  is_defaultable< typename T::value_type >::value &&
100  !traits::is_string< T > &&
101  !traits::is_tensorT< T > > >
102 {
104  static constexpr bool has_default_value = true;
105 
107  using value_type = typename T::value_type;
108 
110  value_type value = value_type();
111 };
112 
113 template< typename T >
114 std::enable_if_t< !Helper< T >::has_default_value, std::ostream & >
115 operator<<( std::ostream & stream, Helper< T > const & GEOS_UNUSED_PARAM( value ) )
116 {
117  return stream;
118 }
119 
120 template< typename T >
121 std::enable_if_t< Helper< T >::has_default_value, std::ostream & >
122 operator<<( std::ostream & stream, Helper< T > const & value )
123 {
124  return stream << value.value;
125 }
126 
127 } // namespace internal
128 
133 template< typename T >
134 using DefaultValue = internal::Helper< T >;
135 
136 } // namespace dataRepository
137 } // namespace geos
138 
139 
140 #endif /* GEOS_DATAREPOSITORY_DEFAULTVALUE_HPP_ */
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:72
std::ostream & operator<<(std::ostream &os, PlotLevel const &plotLevel)
Writes a plot level to a stream.
internal::Helper< T > DefaultValue
A templated alias to hold default values.