Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
StorageComponent.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
20#include "shambase/memory.hpp"
22
23namespace shambase {
24
34 template<class T>
36 private:
37 std::unique_ptr<T> hndl;
38
39 public:
52 void set(T &&arg, SourceLocation loc = SourceLocation()) {
54 if (bool(hndl)) {
56 "please reset the storage component before", loc);
57 }
58 hndl = std::make_unique<T>(std::forward<T>(arg));
59 }
60
75 return shambase::get_check_ref(hndl, loc);
76 }
77
84 void reset() {
86 hndl.reset();
87 }
96 bool is_empty() { return !bool(hndl); }
97 };
98
99} // namespace shambase
Source location utility.
Helper class for Storage Module of any solver.
void set(T &&arg, SourceLocation loc=SourceLocation())
Replace the held object by moving the given argument.
void reset()
Reset the storage component.
bool is_empty()
Check if the storage component is empty.
T & get(SourceLocation loc=SourceLocation())
Get the reference to the held object if it was allocated.
namespace for basic c++ utilities
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:110
This file contains the definition for the stacktrace related functionality.
provide information about the source location