Пример endian

This commit is contained in:
Andrei Astafev 2020-05-15 20:12:52 +03:00
parent 24cb2afb8e
commit 27b3f4182a
5 changed files with 127 additions and 23 deletions

View File

@ -46,6 +46,7 @@ add_subdirectory(src/myx/qt)
# Примеры # Примеры
if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO) if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO)
add_subdirectory(examples/base)
add_subdirectory(examples/filesystem) add_subdirectory(examples/filesystem)
add_subdirectory(examples/qt) add_subdirectory(examples/qt)
endif() endif()

View File

@ -0,0 +1,77 @@
# Название основной цели в текущем каталоге
set(TRGT example-endian-minimal)
# Список файлов исходных текстов
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian.cpp)
if(MYXLIB_BUILD_EXAMPLES)
# Путь поиска библиотек внутри проекта
link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
# Цель для создания исполняемого файла
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
common_target_properties(${TRGT})
# Создание цели для проверки утилитой clang-tidy
add_clang_tidy_check(${TRGT} ${TRGT_cpp})
# Создание цели для проверки утилитой clang-analyze
add_clang_analyze_check(${TRGT} ${TRGT_cpp})
# Создание цели для проверки утилитой clazy
add_clazy_check(${TRGT} ${TRGT_cpp})
# Создание цели для проверки утилитой pvs-studio
add_pvs_check(${TRGT})
# Создание цели для автоматического форматирования кода
add_format_sources(${TRGT} ${TRGT_cpp})
# Qt5
target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
add_dependencies(${TRGT} base)
target_link_libraries(${TRGT} base_static)
target_link_libraries(${TRGT} Qt5::Core)
target_link_libraries(${TRGT} Threads::Threads)
# Имя выходного файла для цели
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME endian-minimal)
add_sanitizers(${TRGT})
cotire(${TRGT})
add_dependencies(${TRGT} create_auxilary_symlinks)
# Правила для установки
install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(MYXLIB_BUILD_EXAMPLES_HO)
# Цель для создания исполняемого файла
add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_qrc})
common_target_properties(${TRGT}-ho)
target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
add_dependencies(${TRGT}-ho base-header-only)
target_link_libraries(${TRGT}-ho Qt5::Core)
target_link_libraries(${TRGT}-ho Threads::Threads)
# Имя выходного файла для цели
set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME endian-minimal-ho)
add_sanitizers(${TRGT}-ho)
cotire(${TRGT}-ho)
add_dependencies(${TRGT}-ho create_auxilary_symlinks)
# Правила для установки
install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

View File

@ -0,0 +1,25 @@
#include <myx/base/config.hpp>
#include <myx/base/endian_types.hpp>
#include <QDebug>
#define CMLIB_PROJECT_NAME "myxlib"
namespace MB = myx::base;
int main( int argc, char** argv )
{
(void)argc;
(void)argv;
beint64 bi = 1;
int64_t bii = reinterpret_cast< int64_t* >( &bi )[0];
qDebug() << hex << bi << bii;
leint64 li = 1;
int64_t lii = reinterpret_cast< int64_t* >( &li )[0];
qDebug() << hex << li << lii;
return( 0 );
} // main

View File

@ -0,0 +1 @@
add_subdirectory(01_endian)

View File

@ -54,8 +54,8 @@ struct is_contiguous_container< T, E, void_t<
template< class T > template< class T >
class span class span
{ {
T* data_ = nullptr; T* m_data = nullptr;
std::size_t size_ = 0; std::size_t m_size = 0;
public: public:
/// The type of value, including cv qualifiers /// The type of value, including cv qualifiers
@ -101,8 +101,8 @@ public:
@param size The number of elements pointed to by `data` @param size The number of elements pointed to by `data`
*/ */
span( T* data, std::size_t size ) : span( T* data, std::size_t size ) :
data_( data ), m_data( data ),
size_( size ) m_size( size )
{ {
} }
@ -118,8 +118,8 @@ public:
> >
explicit explicit
span( ContiguousContainer&& container ) : span( ContiguousContainer&& container ) :
data_( container.data() ), m_data( container.data() ),
size_( container.size() ) m_size( container.size() )
{ {
} }
@ -127,8 +127,8 @@ public:
template< class CharT, class Traits, class Allocator > template< class CharT, class Traits, class Allocator >
explicit explicit
span( std::basic_string< CharT, Traits, Allocator >& s ) : span( std::basic_string< CharT, Traits, Allocator >& s ) :
data_( &s[0] ), m_data( &s[0] ),
size_( s.size() ) m_size( s.size() )
{ {
} }
@ -136,8 +136,8 @@ public:
template< class CharT, class Traits, class Allocator > template< class CharT, class Traits, class Allocator >
explicit explicit
span( std::basic_string< CharT, Traits, Allocator > const& s ) : span( std::basic_string< CharT, Traits, Allocator > const& s ) :
data_( s.data() ), m_data( s.data() ),
size_( s.size() ) m_size( s.size() )
{ {
} }
@ -152,8 +152,8 @@ public:
span& >::type span& >::type
operator=( ContiguousContainer&& container ) operator=( ContiguousContainer&& container )
{ {
data_ = container.data(); m_data = container.data();
size_ = container.size(); m_size = container.size();
return( *this ); return( *this );
} }
@ -163,8 +163,8 @@ public:
operator=( std::basic_string< operator=( std::basic_string<
CharT, Traits, Allocator >& s ) CharT, Traits, Allocator >& s )
{ {
data_ = &s[0]; m_data = &s[0];
size_ = s.size(); m_size = s.size();
return( *this ); return( *this );
} }
@ -174,8 +174,8 @@ public:
operator=( std::basic_string< operator=( std::basic_string<
CharT, Traits, Allocator > const& s ) CharT, Traits, Allocator > const& s )
{ {
data_ = s.data(); m_data = s.data();
size_ = s.size(); m_size = s.size();
return( *this ); return( *this );
} }
@ -184,7 +184,7 @@ public:
bool bool
empty() const empty() const
{ {
return( size_ == 0 ); return( m_size == 0 );
} }
@ -192,7 +192,7 @@ public:
T* T*
data() const data() const
{ {
return( data_ ); return( m_data );
} }
@ -200,7 +200,7 @@ public:
std::size_t std::size_t
size() const size() const
{ {
return( size_ ); return( m_size );
} }
@ -208,7 +208,7 @@ public:
iterator iterator
begin() const begin() const
{ {
return( data_ ); return( m_data );
} }
@ -216,7 +216,7 @@ public:
const_iterator const_iterator
cbegin() const cbegin() const
{ {
return( data_ ); return( m_data );
} }
@ -224,7 +224,7 @@ public:
iterator iterator
end() const end() const
{ {
return( data_ + size_ ); return( m_data + m_size );
} }
@ -232,7 +232,7 @@ public:
const_iterator const_iterator
cend() const cend() const
{ {
return( data_ + size_ ); return( m_data + m_size );
} }
}; // class span }; // class span