mirror of
https://github.com/serge1/ELFIO.git
synced 2024-12-27 12:17:28 +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)
|
if(IS_TOP_PROJECT)
|
||||||
# Enable C++11 for examples and tests
|
# Enable C++11 for examples and tests
|
||||||
if(ELFIO_BUILD_EXAMPLES OR ELFIO_BUILD_TESTS)
|
if(ELFIO_BUILD_EXAMPLES OR ELFIO_BUILD_TESTS)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ELFIO_BUILD_EXAMPLES)
|
if(ELFIO_BUILD_EXAMPLES)
|
||||||
|
@ -141,13 +141,19 @@ class elfio
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
bool load( const std::string& file_name, bool is_lazy = false ) noexcept
|
bool load( const std::string& file_name, bool is_lazy = false ) noexcept
|
||||||
{
|
{
|
||||||
std::ifstream stream;
|
pstream = std::make_unique<std::ifstream>();
|
||||||
stream.open( file_name.c_str(), std::ios::in | std::ios::binary );
|
pstream->open( file_name.c_str(), std::ios::in | std::ios::binary );
|
||||||
if ( !stream ) {
|
if ( pstream == nullptr || !*pstream ) {
|
||||||
return false;
|
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:
|
private:
|
||||||
std::ifstream* pstream = nullptr;
|
std::unique_ptr<std::ifstream> pstream = nullptr;
|
||||||
std::unique_ptr<elf_header> header = nullptr;
|
std::unique_ptr<elf_header> header = nullptr;
|
||||||
std::vector<std::unique_ptr<section>> sections_;
|
std::vector<std::unique_ptr<section>> sections_;
|
||||||
std::vector<std::unique_ptr<segment>> segments_;
|
std::vector<std::unique_ptr<segment>> segments_;
|
||||||
|
Loading…
Reference in New Issue
Block a user