Пример endian
This commit is contained in:
parent
24cb2afb8e
commit
27b3f4182a
@ -46,6 +46,7 @@ add_subdirectory(src/myx/qt)
|
||||
|
||||
# Примеры
|
||||
if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO)
|
||||
add_subdirectory(examples/base)
|
||||
add_subdirectory(examples/filesystem)
|
||||
add_subdirectory(examples/qt)
|
||||
endif()
|
||||
|
77
examples/base/01_endian/CMakeLists.txt
Normal file
77
examples/base/01_endian/CMakeLists.txt
Normal 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()
|
25
examples/base/01_endian/endian.cpp
Normal file
25
examples/base/01_endian/endian.cpp
Normal 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
|
1
examples/base/CMakeLists.txt
Normal file
1
examples/base/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_subdirectory(01_endian)
|
@ -54,8 +54,8 @@ struct is_contiguous_container< T, E, void_t<
|
||||
template< class T >
|
||||
class span
|
||||
{
|
||||
T* data_ = nullptr;
|
||||
std::size_t size_ = 0;
|
||||
T* m_data = nullptr;
|
||||
std::size_t m_size = 0;
|
||||
|
||||
public:
|
||||
/// The type of value, including cv qualifiers
|
||||
@ -101,8 +101,8 @@ public:
|
||||
@param size The number of elements pointed to by `data`
|
||||
*/
|
||||
span( T* data, std::size_t size ) :
|
||||
data_( data ),
|
||||
size_( size )
|
||||
m_data( data ),
|
||||
m_size( size )
|
||||
{
|
||||
}
|
||||
|
||||
@ -118,8 +118,8 @@ public:
|
||||
>
|
||||
explicit
|
||||
span( ContiguousContainer&& container ) :
|
||||
data_( container.data() ),
|
||||
size_( container.size() )
|
||||
m_data( container.data() ),
|
||||
m_size( container.size() )
|
||||
{
|
||||
}
|
||||
|
||||
@ -127,8 +127,8 @@ public:
|
||||
template< class CharT, class Traits, class Allocator >
|
||||
explicit
|
||||
span( std::basic_string< CharT, Traits, Allocator >& s ) :
|
||||
data_( &s[0] ),
|
||||
size_( s.size() )
|
||||
m_data( &s[0] ),
|
||||
m_size( s.size() )
|
||||
{
|
||||
}
|
||||
|
||||
@ -136,8 +136,8 @@ public:
|
||||
template< class CharT, class Traits, class Allocator >
|
||||
explicit
|
||||
span( std::basic_string< CharT, Traits, Allocator > const& s ) :
|
||||
data_( s.data() ),
|
||||
size_( s.size() )
|
||||
m_data( s.data() ),
|
||||
m_size( s.size() )
|
||||
{
|
||||
}
|
||||
|
||||
@ -152,8 +152,8 @@ public:
|
||||
span& >::type
|
||||
operator=( ContiguousContainer&& container )
|
||||
{
|
||||
data_ = container.data();
|
||||
size_ = container.size();
|
||||
m_data = container.data();
|
||||
m_size = container.size();
|
||||
return( *this );
|
||||
}
|
||||
|
||||
@ -163,8 +163,8 @@ public:
|
||||
operator=( std::basic_string<
|
||||
CharT, Traits, Allocator >& s )
|
||||
{
|
||||
data_ = &s[0];
|
||||
size_ = s.size();
|
||||
m_data = &s[0];
|
||||
m_size = s.size();
|
||||
return( *this );
|
||||
}
|
||||
|
||||
@ -174,8 +174,8 @@ public:
|
||||
operator=( std::basic_string<
|
||||
CharT, Traits, Allocator > const& s )
|
||||
{
|
||||
data_ = s.data();
|
||||
size_ = s.size();
|
||||
m_data = s.data();
|
||||
m_size = s.size();
|
||||
return( *this );
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ public:
|
||||
bool
|
||||
empty() const
|
||||
{
|
||||
return( size_ == 0 );
|
||||
return( m_size == 0 );
|
||||
}
|
||||
|
||||
|
||||
@ -192,7 +192,7 @@ public:
|
||||
T*
|
||||
data() const
|
||||
{
|
||||
return( data_ );
|
||||
return( m_data );
|
||||
}
|
||||
|
||||
|
||||
@ -200,7 +200,7 @@ public:
|
||||
std::size_t
|
||||
size() const
|
||||
{
|
||||
return( size_ );
|
||||
return( m_size );
|
||||
}
|
||||
|
||||
|
||||
@ -208,7 +208,7 @@ public:
|
||||
iterator
|
||||
begin() const
|
||||
{
|
||||
return( data_ );
|
||||
return( m_data );
|
||||
}
|
||||
|
||||
|
||||
@ -216,7 +216,7 @@ public:
|
||||
const_iterator
|
||||
cbegin() const
|
||||
{
|
||||
return( data_ );
|
||||
return( m_data );
|
||||
}
|
||||
|
||||
|
||||
@ -224,7 +224,7 @@ public:
|
||||
iterator
|
||||
end() const
|
||||
{
|
||||
return( data_ + size_ );
|
||||
return( m_data + m_size );
|
||||
}
|
||||
|
||||
|
||||
@ -232,7 +232,7 @@ public:
|
||||
const_iterator
|
||||
cend() const
|
||||
{
|
||||
return( data_ + size_ );
|
||||
return( m_data + m_size );
|
||||
}
|
||||
}; // class span
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user