Skip to content

Commit 50a8f62

Browse files
committed
Remove fatal errors from node description and fix memory leaks
1 parent 73fb369 commit 50a8f62

5 files changed

Lines changed: 26 additions & 32 deletions

File tree

flatdata-cpp/include/flatdata/Archive.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,26 +136,14 @@ class Archive
136136

137137
template < typename ResourceType >
138138
std::string
139-
get_description( const ResourceType& resource,
140-
bool is_archive,
141-
bool initialized,
142-
size_t nest_level )
139+
get_description( const ResourceType& resource, bool is_archive, size_t nest_level )
143140
{
144141
std::string description;
145142
if ( is_archive )
146143
{
147144
++nest_level;
148145
}
149-
150-
if ( initialized )
151-
{
152-
description = resource.describe( nest_level );
153-
}
154-
else
155-
{
156-
auto dummy = new ResourceType( );
157-
description = dummy->describe( nest_level );
158-
}
146+
description = resource.describe( nest_level );
159147
return description;
160148
}
161149

@@ -171,8 +159,8 @@ Archive::describe_resource( size_t nest_level,
171159
const bool is_archive = std::is_base_of< Archive, ResourceType >::value;
172160

173161
describe_impl( stream, name, false, initialized,
174-
get_description( resource, is_archive, initialized, nest_level ).c_str( ),
175-
is_archive, too_large, nest_level );
162+
get_description( resource, is_archive, nest_level ).c_str( ), is_archive,
163+
too_large, nest_level );
176164
}
177165

178166
template < typename ResourceType >
@@ -186,12 +174,12 @@ Archive::describe_resource( size_t nest_level,
186174
const auto initialized = static_cast< bool >( resource );
187175
const bool is_archive = std::is_base_of< Archive, ResourceType >::value;
188176

189-
const ResourceType ref = initialized ? *resource // valid ref
190-
: *( new ResourceType( ) ); // ref to dummy, not used
177+
const ResourceType ref = initialized ? *resource // valid ref
178+
: ResourceType( ); // ref to dummy, not used
191179

192180
describe_impl( stream, name, true, initialized ? static_cast< bool >( *resource ) : false,
193-
get_description( ref, is_archive, initialized, nest_level ).c_str( ), is_archive,
194-
too_large, nest_level );
181+
get_description( ref, is_archive, nest_level ).c_str( ), is_archive, too_large,
182+
nest_level );
195183
}
196184

197185
template < typename ResourceType >

flatdata-cpp/include/flatdata/ArrayView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ArrayView
4444

4545
size_t size_in_bytes( ) const;
4646
size_t size( ) const;
47-
std::string describe( size_t unused = 0u ) const;
47+
std::string describe( size_t nest_level = 0u ) const;
4848

4949
bool empty( ) const;
5050

flatdata-cpp/include/flatdata/MemoryDescriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct MemoryDescriptor
3131
}
3232

3333
std::string
34-
describe( size_t unused = 0 ) const
34+
describe( size_t nest_level = 0 ) const
3535
{
3636
std::ostringstream ss;
3737
if ( this->operator bool( ) )

flatdata-cpp/src/Archive.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,15 @@ Archive::describe( size_t nest_level ) const
239239

240240
if ( !m_storage )
241241
{
242-
result << ( is_root_node ? hline : empty )
243-
<< "FATAL: Resource storage not initialized. Please check archive path."
244-
<< ( is_root_node ? newl : empty );
242+
if ( is_root_node )
243+
{
244+
result << hline << "FATAL: Resource storage not initialized. Please check archive path."
245+
<< newl;
246+
}
247+
else
248+
{
249+
result << "Uninitialized Archive " << name( );
250+
}
245251
}
246252

247253
if ( m_storage && !m_signature )
@@ -294,7 +300,7 @@ Archive::describe_impl( std::ostream& stream,
294300
bool optional,
295301
bool loaded,
296302
const char* details,
297-
bool are_details_nested,
303+
bool has_nested_details,
298304
bool too_large,
299305
size_t nest_level )
300306
{
@@ -305,7 +311,7 @@ Archive::describe_impl( std::ostream& stream,
305311
<< std::setfill( ' ' ) << ( optional ? "YES" : "NO" ) << std::left << std::setw( 11 )
306312
<< std::setfill( ' ' ) << ( too_large ? "YES" : "NO" ) << std::left << std::setw( 10 )
307313
<< std::setfill( ' ' ) << ( static_cast< bool >( loaded ) ? "YES" : "NO" ) << details
308-
<< ( are_details_nested ? "" : "\n" );
314+
<< ( has_nested_details ? "" : "\n" );
309315
}
310316

311317
} // namespace flatdata

flatdata-cpp/test/GeneratedArchiveTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Resource Optional Too Large Loaded Details
356356
================================================================================
357357
outer1 NO NO YES Structure of size 1
358358
outer2 NO NO YES Structure of size 1
359-
inner NO NO NO FATAL: Resource storage not initialized. Please check archive path.
359+
inner NO NO NO Uninitialized Archive InnerArchive
360360
|
361361
|-> Flatdata Archive: InnerArchive
362362
inner NO NO NO Uninitialized Structure AStruct
@@ -390,7 +390,7 @@ Flatdata Archive: OuterWithOptional
390390
Resource Optional Too Large Loaded Details
391391
================================================================================
392392
outer NO NO YES Structure of size 1
393-
archive_resource YES NO NO FATAL: Resource storage not initialized. Please check archive path.
393+
archive_resource YES NO NO Uninitialized Archive InnerArchive
394394
|
395395
|-> Flatdata Archive: InnerArchive
396396
inner NO NO NO Uninitialized Structure AStruct
@@ -608,12 +608,12 @@ Flatdata Archive: OutermostArchive
608608
Resource Optional Too Large Loaded Details
609609
================================================================================
610610
outermost NO NO NO Uninitialized Structure AStruct
611-
outer NO NO NO FATAL: Resource storage not initialized. Please check archive path.
611+
outer NO NO NO Uninitialized Archive OuterArchive
612612
|
613613
|-> Flatdata Archive: OuterArchive
614614
outer1 NO NO NO Uninitialized Structure AStruct
615615
outer2 NO NO NO Uninitialized Structure AStruct
616-
inner NO NO NO FATAL: Resource storage not initialized. Please check archive path.
616+
inner NO NO NO Uninitialized Archive InnerArchive
617617
|
618618
|-> Flatdata Archive: InnerArchive
619619
inner NO NO NO Uninitialized Structure AStruct
@@ -672,7 +672,7 @@ Flatdata Archive: OuterWithOptional
672672
Resource Optional Too Large Loaded Details
673673
================================================================================
674674
outer NO NO NO Uninitialized Structure AStruct
675-
archive_resource YES NO NO FATAL: Resource storage not initialized. Please check archive path.
675+
archive_resource YES NO NO Uninitialized Archive InnerArchive
676676
|
677677
|-> Flatdata Archive: InnerArchive
678678
inner NO NO NO Uninitialized Structure AStruct

0 commit comments

Comments
 (0)