ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
message.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_basecamp of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_CAMP_MESSAGE_MESSAGE
9#define HPP_ALIB_CAMP_MESSAGE_MESSAGE 1
10
11#if !defined (HPP_ALIB_STRINGS_CSTRING)
13#endif
14
16
17#if !defined(HPP_ALIB_BOXING_ENUM)
18# include "alib/boxing/enum.hpp"
19#endif
20
21#if !defined (HPP_ALIB_MONOMEM_SELF_CONTAINED)
23#endif
24
25
26namespace alib::lang {
27
28/** ************************************************************************************************
29 * This struct stores a list of information objects of arbitrary type by publically inheriting type
30 * \alib{boxing;Boxes}. In addition, source code location information is attached, which usually
31 * refers to the place of construction of an instance of this type.<br>
32 * Finally, a type identifier is available with field #Type.
33 *
34 * Note that while message data might be passed with construction, informational data may be added,
35 * changed or removed during the life-cycle of an instance using the inherited interface of
36 * class \alib{boxing;Boxes}.
37 *
38 *
39 * Inside \alib, the struct is used with types \alib{lang;Exception} and \alib{lang;Report}.
40 *
41 **************************************************************************************************/
42struct Message : public Boxes
43{
44 public:
45 /** The file name that this message relates to. */
47
48 /** The line number within #File, that this message relates to. */
49 int Line;
50
51 /** The function/method name that this message relates to. */
53
54 /**
55 * A type identifier, defined with construction by providing an element of arbitrary
56 * enumeration type.
57 */
59
60 protected:
61 /**
62 * Denotes whether this instance is responsible for deleting the (inherited) monotonic
63 * allocator or not.
64 */
66
67 public:
68 /** ****************************************************************************************
69 * Constructs a message that does not use a \alib{monomem;MonoAllocator} and therefore
70 * uses dynamic memory allocation for storing the boxable arguments.
71 * @param file Information about the scope of invocation.
72 * @param line Information about the scope of invocation.
73 * @param function Information about the scope of invocation.
74 * @param type The message type.
75 * @param args Variadic, templated list of arguments.
76 ******************************************************************************************/
77 template <typename... TBoxables>
78 Message( const NCString& file, int line, const NCString& function,
79 const Enum& type, TBoxables&&... args )
80 : Boxes( nullptr)
81 , File(file), Line(line), Function(function), Type(type)
83 {
84 Add( std::forward<TBoxables>(args)... );
85 }
86
87 /** ****************************************************************************************
88 * Constructs a message that uses a \alib{monomem;MonoAllocator} to store the boxable
89 * arguments. If parameter \p{monoAllocatorResp} equals \b Responsibility::Transfer, then
90 * this destructor of this class will delete the object given with \p{monoAllocator}.
91 *
92 * @param file Information about the scope of invocation.
93 * @param line Information about the scope of invocation.
94 * @param function Information about the scope of invocation.
95 * @param monoAllocator The allocator to store the arguments in.
96 * @param monoAllocatorResp The responsibility for the allocator.
97 * @param type The message type.
98 * @param args Variadic, templated list of arguments.
99 ******************************************************************************************/
100 template <typename... TBoxables>
101 Message( const NCString& file, int line, const NCString& function,
102 MonoAllocator* monoAllocator, lang::Responsibility monoAllocatorResp,
103 const Enum& type, TBoxables&&... args )
104 : Boxes( monoAllocator )
105 , File(file), Line(line), Function( function), Type( type)
106 , monoAllocatorResponsibility(monoAllocatorResp)
107 {
108 Add( std::forward<TBoxables>(args)... );
109 }
110
111 /** ****************************************************************************************
112 * Destructor. If a monotonic allocator was provided in the constructor along with
113 * flag \b Responsibility::Transfer, this allocator is deleted.
114 ******************************************************************************************/
116 {}
117
118 /** ****************************************************************************************
119 * Loops over all contained boxes and invokes box-function \alib{boxing;FClone}.
120 * The monotonic allocator passed in the constructor of this message is passed to \b FClone.
121 * If no allocator was passed in the constructor, this method must not be invoked.
122 * This condition is asserted in debug-compilations.
123 *
124 * It is the responsibility of the user or creator of a message object to invoke this method
125 * and to ensure that objects that are referenced in the stored boxes either survive the
126 * lifetime of the methods or are duly cloned.
127 *
128 * \see
129 * Manual chapter \ref alib_basecamp_message_message_lifecycle for details.
130 ******************************************************************************************/
132 {
133 CloneAll( *get_allocator().allocator );
134 }
135
136
137};
138
139} // namespace [alib::lang]
140
141
142// Customize boxing of type Message to its parent type Boxes. This allows to "flatten" all
143// arguments stored in a message when added to an instance of Boxes.
145
146
147#endif // HPP_ALIB_CAMP_MESSAGE_MESSAGE
ALIB_API void CloneAll(monomem::MonoAllocator &memory)
Definition boxing.cpp:216
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING(TSource, TTarget)
@ KeepWithSender
Keeps responsibility, e.g. when passing an object.
Message(const NCString &file, int line, const NCString &function, MonoAllocator *monoAllocator, lang::Responsibility monoAllocatorResp, const Enum &type, TBoxables &&... args)
Definition message.hpp:101
lang::Responsibility monoAllocatorResponsibility
Definition message.hpp:65
Message(const NCString &file, int line, const NCString &function, const Enum &type, TBoxables &&... args)
Definition message.hpp:78