mirror of
https://github.com/serge1/ELFIO.git
synced 2025-04-17 08:44:25 +00:00
C++17 refactoring
This commit is contained in:
parent
5a9297b1bd
commit
8ae6cec5d6
@ -41,11 +41,8 @@ THE SOFTWARE.
|
||||
#include <elfio/elfio_segment.hpp>
|
||||
#include <elfio/elfio_strings.hpp>
|
||||
|
||||
#define ELFIO_HEADER_ACCESS_GET( TYPE, FNAME ) \
|
||||
TYPE get_##FNAME() const \
|
||||
{ \
|
||||
return header ? ( header->get_##FNAME() ) : 0; \
|
||||
}
|
||||
#define ELFIO_HEADER_ACCESS_GET( TYPE, FNAME ) \
|
||||
TYPE get_##FNAME() const { return header ? ( header->get_##FNAME() ) : 0; }
|
||||
|
||||
#define ELFIO_HEADER_ACCESS_GET_SET( TYPE, FNAME ) \
|
||||
TYPE get_##FNAME() const \
|
||||
@ -421,9 +418,7 @@ class elfio
|
||||
//------------------------------------------------------------------------------
|
||||
section* create_section()
|
||||
{
|
||||
unsigned char file_class = get_class();
|
||||
|
||||
if ( file_class == ELFCLASS64 ) {
|
||||
if ( auto file_class = get_class(); file_class == ELFCLASS64 ) {
|
||||
sections_.emplace_back(
|
||||
new ( std::nothrow ) section_impl<Elf64_Shdr>(
|
||||
&convertor, &addr_translator, compression ) );
|
||||
@ -447,9 +442,7 @@ class elfio
|
||||
//------------------------------------------------------------------------------
|
||||
segment* create_segment()
|
||||
{
|
||||
unsigned char file_class = header->get_class();
|
||||
|
||||
if ( file_class == ELFCLASS64 ) {
|
||||
if ( auto file_class = header->get_class(); file_class == ELFCLASS64 ) {
|
||||
segments_.emplace_back(
|
||||
new ( std::nothrow )
|
||||
segment_impl<Elf64_Phdr>( &convertor, &addr_translator ) );
|
||||
@ -512,9 +505,8 @@ class elfio
|
||||
sec->set_address( sec->get_address() );
|
||||
}
|
||||
|
||||
Elf_Half shstrndx = get_section_name_str_index();
|
||||
|
||||
if ( SHN_UNDEF != shstrndx ) {
|
||||
if ( Elf_Half shstrndx = get_section_name_str_index();
|
||||
SHN_UNDEF != shstrndx ) {
|
||||
string_section_accessor str_reader( sections[shstrndx] );
|
||||
for ( Elf_Half i = 0; i < num; ++i ) {
|
||||
Elf_Word section_offset = sections[i]->get_name_string_offset();
|
||||
@ -733,8 +725,8 @@ class elfio
|
||||
if ( is_section_without_segment( i ) ) {
|
||||
const auto& sec = sections_[i];
|
||||
|
||||
Elf_Xword section_align = sec->get_addr_align();
|
||||
if ( section_align > 1 &&
|
||||
if ( Elf_Xword section_align = sec->get_addr_align();
|
||||
section_align > 1 &&
|
||||
current_file_pos % section_align != 0 ) {
|
||||
current_file_pos +=
|
||||
section_align - current_file_pos % section_align;
|
||||
@ -966,7 +958,7 @@ class elfio
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
section* operator[]( const std::string& name ) const
|
||||
section* operator[]( const std::string_view& name ) const
|
||||
{
|
||||
section* sec = nullptr;
|
||||
|
||||
|
@ -23,7 +23,7 @@ THE SOFTWARE.
|
||||
#ifndef ELFIO_MODINFO_HPP
|
||||
#define ELFIO_MODINFO_HPP
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace ELFIO {
|
||||
@ -56,12 +56,12 @@ template <class S> class modinfo_section_accessor_template
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool get_attribute( const std::string& field_name,
|
||||
std::string& value ) const
|
||||
bool get_attribute( const std::string_view& field_name,
|
||||
std::string& value ) const
|
||||
{
|
||||
for ( auto& i : content ) {
|
||||
if ( field_name == i.first ) {
|
||||
value = i.second;
|
||||
for ( const auto [first, second] : content ) {
|
||||
if ( field_name == first ) {
|
||||
value = second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ template <class T> class section_impl : public section
|
||||
Elf_Xword size = get_size();
|
||||
Elf_Xword uncompressed_size = 0;
|
||||
auto decompressed_data = compression->inflate(
|
||||
data.get(), convertor, size, uncompressed_size );
|
||||
data.get(), convertor, size, uncompressed_size );
|
||||
if ( decompressed_data != nullptr ) {
|
||||
set_size( uncompressed_size );
|
||||
data = std::move( decompressed_data );
|
||||
@ -338,7 +338,7 @@ template <class T> class section_impl : public section
|
||||
Elf_Xword decompressed_size = get_size();
|
||||
Elf_Xword compressed_size = 0;
|
||||
auto compressed_ptr = compression->deflate(
|
||||
data.get(), convertor, decompressed_size, compressed_size );
|
||||
data.get(), convertor, decompressed_size, compressed_size );
|
||||
stream.write( compressed_ptr.get(), compressed_size );
|
||||
}
|
||||
else {
|
||||
|
@ -177,11 +177,11 @@ class address_translator
|
||||
{
|
||||
addr_translations = addr_trans;
|
||||
|
||||
std::sort(
|
||||
addr_translations.begin(), addr_translations.end(),
|
||||
[]( address_translation& a, address_translation& b ) -> bool {
|
||||
return a.start < b.start;
|
||||
} );
|
||||
std::sort( addr_translations.begin(), addr_translations.end(),
|
||||
[]( const address_translation& a,
|
||||
const address_translation& b ) -> bool {
|
||||
return a.start < b.start;
|
||||
} );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -236,8 +236,7 @@ inline std::string to_hex_string( uint64_t value )
|
||||
std::string str;
|
||||
|
||||
while ( value ) {
|
||||
auto digit = value & 0xF;
|
||||
if ( digit < 0xA ) {
|
||||
if ( auto digit = value & 0xF; digit < 0xA ) {
|
||||
str = char( '0' + digit ) + str;
|
||||
}
|
||||
else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user