ALib C++ Library
Library Version: 2412 R0
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 !DOXYGEN
19# include <algorithm>
20#endif // !DOXYGEN
21
22
24
25
26namespace alib::lang {
27
29{
30 enums::EnumRecordParser::Get( ERSerializable::EnumElementName );
31 ERSerializable::MinimumRecognitionLength= 0;
33}
34
36{
37 // find pointer to the last entry pointer;
38 detail::ExceptionEntry** tail= &**this;
39 while(*tail != nullptr)
40 tail= &(*tail)->next;
41
42 *tail= GetAllocator()().Alloc<detail::ExceptionEntry>();
43 (*tail)->next= nullptr;
44
45 return &(*tail)->message;
46}
47
48
49void Exception::finalizeMessage( Message* message, bool hasRecord, ResourcePool* pool, const NString& category )
50{
51 message->CloneAll();
52
53 if( hasRecord )
54 {
55 #if ALIB_DEBUG
56 {
57 auto* tryRecord= message->Type.TryRecord<ERException>();
58 if( tryRecord == nullptr )
59 {
60 std::vector<std::pair<integer,const void*>> recordList;
61 for( auto& record : enums::detail::getInternalRecordMap() )
62 if( record.first.RTTI == message->Type.TypeID() )
63 recordList.push_back( std::pair<integer,const void*>(record.first.Element, record.second) );
64 if( recordList.size() == 0)
65 {
66 ALIB_ERROR( "EXCEPT", "No enum records defined for exception enumeration type {!Q<>}.",
67 message->Type.TypeID().name() )
68 }
69 else
70 {
71 std::sort( recordList.begin(), recordList.end(),
72 [] (std::pair<integer,const void*>& a, std::pair<integer,const void*>& b )
73 {
74 return a.first < b.first;
75 });
76 AString recordListDump;
78 Formatter& formatter= *Formatter::Default;
79 formatter.GetArgContainer();
80 formatter.Format( recordListDump,
81 "Enum record {} not found for exception enumeration type {}.\n"
82 "The following records have been found:\n",
83 message->Type.Integral(),
84 message->Type.TypeID() );
85
86 for( auto& pair : recordList )
87 formatter.Format( recordListDump, " {:2}: {}\n",
88 pair.first,
89 reinterpret_cast<const ERException*>( pair.second )->EnumElementName );
90 ALIB_ERROR( "EXCEPT", recordListDump )
91 }
92 }
93 }
94 #endif
95 const auto& enumRecord= message->Type.GetRecord<ERException>();
96 if( pool == nullptr )
97 message->emplace( message->begin(),
98 enumRecord.DescriptionOrItsResourceName );
99 else
100 message->emplace( message->begin(),
101 pool->Get( category,
102 enumRecord.DescriptionOrItsResourceName
103 ALIB_DBG(, true) ) );
104 }
105}
106
107
109{
110 auto* result= **this;
111 while( result->next != nullptr )
112 result= result->next;
113
114 return result->message;
115}
116
118{
119 int result= 1;
120 auto* entry= **this;
121 while( entry->next != nullptr )
122 {
123 entry= entry->next;
124 ++result;
125 }
126
127 return result;
128}
129
130const Enum& Exception::Type() const
131{
132 auto* entry= **this;
133 Enum* result= &entry->message.Type;
134 while( (entry= entry->next) != nullptr )
135 if( entry->message.Type.Integral() >= 0 )
136 result= &entry->message.Type;
137
138 return *result;
139}
140
141
142
144{
145 Paragraphs text(target);
146 Tokenizer tknzr;
147 tknzr.TrimChars= A_CHAR( "\r" );
148 String1K buf;
150 Formatter& formatter= *Formatter::Default;
151 formatter.GetArgContainer();
152 size_t entryNo= 1;
153 for ( auto entry= begin(); entry != end(); ++entry )
154 {
155 text.Add( A_CHAR("{}{}: {!Q<>}"), (entry->Type.Integral() >= 0 ? 'E' : 'I'), entryNo, entry->Type );
156 text.PushIndent( A_CHAR(" ") );
157 try
158 {
159 formatter.FormatArgs( buf.Reset(), *entry );
160 }
161 catch( Exception& e )
162 {
163 buf << BASECAMP.GetResource("ExcFmtExc");
164 e.Format( buf );
165 }
166 tknzr.Set( buf, '\n' );
167 while( tknzr.HasNext() )
168 text.Add( tknzr.Next() );
169
170 #if ALIB_DEBUG
171 text.Add( entry->CI );
172 #endif
173
174 text.PopIndent();
175 ++entryNo;
176 }
177
178 return target;
179}
180
181} // 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:35
ForwardIterator begin()
ForwardIterator end()
ALIB_API void finalizeMessage(Message *message, bool hasRecord, ResourcePool *pool, const NString &category)
Definition exception.cpp:49
ALIB_API AString & Format(AString &target) const
static ALIB_API threads::RecursiveLock DefaultLock
static ALIB_API SPFormatter Default
Formatter & FormatArgs(AString &target)
Formatter & Format(AString &target, TArgs &&... args)
virtual BoxesMA & GetArgContainer()
ALIB_API Paragraphs & PushIndent(uinteger qty, character fillChar=' ')
void Add(boxing::TBoxes< TAllocatorArgs > &args)
ALIB_API Paragraphs & PopIndent()
virtual const String & Get(const NString &category, const NString &name, bool dbgAssert)=0
void DbgDisableBufferReplacementWarning()
Definition tastring.inl:363
TLocalString< TChar, 8 > TrimChars
Definition tokenizer.hpp:77
ALIB_API TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
Definition tokenizer.cpp:16
void Set(const TString< TChar > &src, TChar delimiter, bool skipEmptyTokens=false)
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
Definition vtable.inl:473
#define A_CHAR(STR)
#define ALIB_ERROR(...)
Definition alib.hpp:1267
#define ALIB_LOCK_RECURSIVE_WITH(lock)
Definition owner.hpp:457
#define ALIB_DBG(...)
Definition alib.hpp:390
HashMap< MonoAllocator, EnumRecordKey, const void *, EnumRecordKey::Hash, EnumRecordKey::EqualTo > & getInternalRecordMap()
Definition records.cpp:77
lang::basecamp::BaseCamp BASECAMP
The singleton instance of ALib Camp class BaseCamp.
Definition basecamp.cpp:70
integer Integral() const
Definition enum.hpp:119
const TRecord & GetRecord()
Definition enum.hpp:301
const TRecord * TryRecord()
Definition enum.hpp:337
const std::type_info & TypeID() const
Definition box.inl:941
String EnumElementName
The name of the enum element.
Definition records.hpp:660
static ALIB_API void Get(String &result, bool isLastField=false)
String DescriptionOrItsResourceName
Definition exception.hpp:56
ALIB_API void Parse()
Definition exception.cpp:28
ExceptionEntry * next
A pointer to the next message.
Definition exception.hpp:29