iceoryx_doc  1.0.1
creation.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 #ifndef IOX_UTILS_DESIGN_PATTERN_CREATION_HPP
18 #define IOX_UTILS_DESIGN_PATTERN_CREATION_HPP
19 
20 #include "iceoryx_utils/cxx/expected.hpp"
21 
22 #include <utility>
23 
24 namespace DesignPattern
25 {
97 template <typename DerivedClass, typename ErrorType>
98 class Creation
99 {
100  public:
102  using result_t = iox::cxx::expected<DerivedClass, ErrorType>;
103  using errorType_t = ErrorType;
104 
111  template <typename... Targs>
112  static result_t create(Targs&&... args) noexcept;
113 
118  static result_t verify(DerivedClass&& newObject) noexcept;
119 
127  template <typename... Targs>
128  static iox::cxx::expected<ErrorType> placementCreate(void* const memory, Targs&&... args) noexcept;
129 
130  Creation() noexcept = default;
131  Creation(Creation&& rhs) noexcept;
132 
133  Creation& operator=(Creation&& rhs) noexcept;
134  Creation(const Creation& rhs) noexcept = default;
135  Creation& operator=(const Creation& rhs) noexcept = default;
136 
138  bool isInitialized() const noexcept;
139 
140  protected:
141  bool m_isInitialized{false};
142  ErrorType m_errorValue;
143 };
144 
145 } // namespace DesignPattern
146 
147 #include "iceoryx_utils/internal/design_pattern/creation.inl"
148 
149 #endif // IOX_UTILS_DESIGN_PATTERN_CREATION_HPP
This pattern can be used if you write an abstraction where you have to throw an exception in the cons...
Definition: creation.hpp:99
bool isInitialized() const noexcept
returns true if the object was constructed successfully, otherwise false
Definition: creation.inl:47
static result_t create(Targs &&... args) noexcept
factory method which guarantees that either a working object is produced or an error value describing...
Definition: creation.inl:41
static iox::cxx::expected< ErrorType > placementCreate(void *const memory, Targs &&... args) noexcept
factory method which guarantees that either a working object is produced or an error value describing...
Definition: creation.inl:66
static result_t verify(DerivedClass &&newObject) noexcept
verifies if a class was created successfully
Definition: creation.inl:54
expected implementation from the C++20 proposal with C++11. The interface is inspired by the proposal...
Definition: expected.hpp:163