ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
exception.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !defined(ALIB_DOX)
10# if !defined (HPP_ALIB_CAMP_MESSAGE_EXCEPTION)
12# endif
13
14# if !defined (HPP_ALIB_STRINGS_UTIL_TOKENIZER)
16# endif
17
18# if !defined (HPP_ALIB_LANG_FORMAT_FORMATTER_STD)
20# endif
21
22# if !defined (HPP_ALIB_LANG_FORMAT_PARAGRAPHS)
24# endif
25
26#if !defined(HPP_ALIB_CAMP_MESSAGE_REPORT)
28#endif
29
30# if !defined (HPP_ALIB_CAMP_MESSAGE_EXCEPTION)
32# endif
33
34# if !defined (HPP_ALIB_ENUMS_RECORDPARSER)
36# endif
37# if !defined (HPP_ALIB_ENUMS_DETAIL_ENUMRECORDMAP)
39# endif
40# if !defined (HPP_ALIB_LANG_CAMP_INLINES)
42# endif
43#endif // !defined(ALIB_DOX)
44
45
47
48
49namespace alib::lang {
50
52{
53 enums::EnumRecordParser::Get( ERSerializable::EnumElementName );
54 ERSerializable::MinimumRecognitionLength= 0;
56}
57
59{
60 // find pointer to the last entry pointer;
62 while(*tail != nullptr)
63 tail= &(*tail)->next;
64
66 (*tail)->next= nullptr;
67
68
69 return &(*tail)->message;
70}
71
72void Exception::finalizeMessage( Message* message, bool hasRecord, ResourcePool* pool, const NString& category )
73{
74 message->CloneArguments();
75
76 if( hasRecord )
77 {
78 #if ALIB_DEBUG
79 {
80 auto* tryRecord= message->Type.TryRecord<ERException>();
81 if( tryRecord == nullptr )
82 {
83 std::vector<std::pair<integer,const void*>> recordList;
84 for( auto& record : enums::detail::getInternalRecordMap() )
85 if( record.first.RTTI == message->Type.TypeID() )
86 recordList.push_back( std::pair<integer,const void*>(record.first.Element, record.second) );
87 if( recordList.size() == 0)
88 {
89 ALIB_ERROR( "EXCEPT", "No enum records defined for exception enumeration type {!Q<>}.",
90 message->Type.TypeID().name() )
91 }
92 else
93 {
94 std::sort( recordList.begin(), recordList.end(),
95 [] (std::pair<integer,const void*>& a, std::pair<integer,const void*>& b )
96 {
97 return a.first < b.first;
98 });
99 AString recordListDump;
101 formatter->Format( recordListDump,
102 "Enum record {} not found for exception enumeration type {}.\n"
103 "The following records have been found:\n",
104 message->Type.Integral(),
105 message->Type.TypeID() );
106
107 for( auto& pair : recordList )
108 formatter->Format( recordListDump, " {:2}: {}\n",
109 pair.first,
110 reinterpret_cast<const ERException*>( pair.second )->EnumElementName );
111 formatter->Release();
112 ALIB_ERROR( "EXCEPT", recordListDump )
113 }
114 }
115 }
116 #endif
117 const auto& enumRecord= message->Type.GetRecord<ERException>();
118 if( pool == nullptr )
119 message->emplace( message->begin(),
120 enumRecord.DescriptionOrItsResourceName );
121 else
122 message->emplace( message->begin(),
123 pool->Get( category,
124 enumRecord.DescriptionOrItsResourceName
125 ALIB_DBG(, true) ) );
126 }
127}
128
129
131{
132 auto* result= Self();
133 while( result->next != nullptr )
134 result= result->next;
135
136 return result->message;
137}
138
140{
141 int result= 1;
142 auto* entry= Self();
143 while( entry->next != nullptr )
144 {
145 entry= entry->next;
146 ++result;
147 }
148
149 return result;
150}
151
152const Enum& Exception::Type() const
153{
154 auto* entry= Self();
155 Enum* result= &entry->message.Type;
156 while( (entry= entry->next) != nullptr )
157 if( entry->message.Type.Integral() >= 0 )
158 result= &entry->message.Type;
159
160 return *result;
161}
162
163
164
166{
167 Paragraphs text(target);
168 Tokenizer tknzr;
169 tknzr.TrimChars= A_CHAR( "\r" );
170 String1K buf;
173 size_t entryNo= 1;
174 for ( auto entry= begin(); entry != end(); ++entry )
175 {
176 text.Add( A_CHAR("{}{}: {!Q<>}"), (entry->Type.Integral() >= 0 ? 'E' : 'I'), entryNo, entry->Type );
177 text.PushIndent( A_CHAR(" ") );
178 try
179 {
180 formatter->FormatArgs( buf.Reset(), *entry );
181 }
182 catch( Exception& e )
183 {
184 buf << BASECAMP.GetResource("ExcFmtExc");
185 e.Format( buf );
186 }
187 tknzr.Set( buf, '\n' );
188 while( tknzr.HasNext() )
189 text.Add( tknzr.Next() );
190
191 text.PopIndent();
192 ++entryNo;
193 }
194
195 formatter->Release();
196 return target;
197}
198
199} // namespace [alib::lang]
const String & GetResource(const NString &name)
ALIB_API Message & Back() const
ALIB_API int Size() const
AString Format() const
ALIB_API const Enum & Type() const
ALIB_API Message * allocMessageLink()
Definition exception.cpp:58
ForwardIterator begin()
ForwardIterator end()
ALIB_API void finalizeMessage(Message *message, bool hasRecord, ResourcePool *pool, const NString &category)
Definition exception.cpp:72
ALIB_API AString & Format(AString &target) const
static SPFormatter AcquireDefault(const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
ALIB_API Paragraphs & PushIndent(uinteger qty, character fillChar=' ')
ALIB_API Paragraphs & PopIndent()
ALIB_API void Add(Boxes &args)
virtual const String & Get(const NString &category, const NString &name, bool dbgAssert)=0
ALIB_FORCE_INLINE char * Alloc(size_t size, size_t alignment)
void DbgDisableBufferReplacementWarning()
Definition astring.hpp:353
TLocalString< TChar, 8 > TrimChars
Definition tokenizer.hpp:90
ALIB_API TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
Definition tokenizer.cpp:18
void Set(const TString< TChar > &src, TChar delimiter, bool skipEmptyTokens=false)
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
Definition vtable.inl:490
#define A_CHAR(STR)
#define ALIB_ERROR(...)
Definition alib.hpp:980
#define ALIB_DBG(...)
Definition alib.hpp:457
#define ALIB_CALLER_PRUNED
Definition alib.hpp:845
const HashMap< EnumRecordKey, const void *, EnumRecordKey::Hash, EnumRecordKey::EqualTo > & getInternalRecordMap()
Definition records.cpp:77
lang::basecamp::BaseCamp BASECAMP
Definition basecamp.cpp:136
std::shared_ptr< lang::format::Formatter > SPFormatter
integer Integral() const
Definition enum.hpp:123
const TRecord & GetRecord()
Definition enum.hpp:305
const TRecord * TryRecord()
Definition enum.hpp:341
const std::type_info & TypeID() const
Definition box.inl:902
static ALIB_API void Get(String &result, bool isLastField=false)
String DescriptionOrItsResourceName
Definition exception.hpp:70
ALIB_API void Parse()
Definition exception.cpp:51
ExceptionEntry * next
A pointer to the next message.
Definition exception.hpp:41