mirror of
https://github.com/serge1/ELFIO.git
synced 2024-12-26 18:15:40 +00:00
Add 'lazy' load for own opened streams
This commit is contained in:
parent
4320ea915e
commit
94505dd637
@ -46,7 +46,7 @@ target_include_directories(
|
||||
if(IS_TOP_PROJECT)
|
||||
# Enable C++11 for examples and tests
|
||||
if(ELFIO_BUILD_EXAMPLES OR ELFIO_BUILD_TESTS)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
endif()
|
||||
|
||||
if(ELFIO_BUILD_EXAMPLES)
|
||||
|
@ -141,13 +141,19 @@ class elfio
|
||||
//------------------------------------------------------------------------------
|
||||
bool load( const std::string& file_name, bool is_lazy = false ) noexcept
|
||||
{
|
||||
std::ifstream stream;
|
||||
stream.open( file_name.c_str(), std::ios::in | std::ios::binary );
|
||||
if ( !stream ) {
|
||||
pstream = std::make_unique<std::ifstream>();
|
||||
pstream->open( file_name.c_str(), std::ios::in | std::ios::binary );
|
||||
if ( pstream == nullptr || !*pstream ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return load( stream, is_lazy );
|
||||
bool ret = load( *pstream, is_lazy );
|
||||
|
||||
if ( !is_lazy ) {
|
||||
pstream.release();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1085,7 +1091,7 @@ class elfio
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
std::ifstream* pstream = nullptr;
|
||||
std::unique_ptr<std::ifstream> pstream = nullptr;
|
||||
std::unique_ptr<elf_header> header = nullptr;
|
||||
std::vector<std::unique_ptr<section>> sections_;
|
||||
std::vector<std::unique_ptr<segment>> segments_;
|
||||
|
Loading…
Reference in New Issue
Block a user