bit7z 4.0.9
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bittypes.hpp
1/*
2 * bit7z - A C++ static library to interface with the 7-zip shared libraries.
3 * Copyright (c) 2014-2023 Riccardo Ostani - All Rights Reserved.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef BITTYPES_HPP
11#define BITTYPES_HPP
12
13#include <string>
14#include <vector>
15
16// Must be included here since the user might have manually enabled a BIT7Z_* compilation option
17// by uncommenting the corresponding macro define in bitdefines.hpp.
18#include "bitdefines.hpp"
19
20#ifdef BIT7Z_REGEX_MATCHING
21#include <regex>
22#endif
23
24namespace bit7z {
25
29#ifdef BIT7Z_USE_STD_BYTE
30#if __cpp_lib_byte
31using byte_t = std::byte;
32#else
33enum class byte_t : unsigned char {}; //same as std::byte_t
34#endif
35#else
36using byte_t = unsigned char;
37#endif
38
40using buffer_t = std::vector< byte_t >;
41using index_t = std::ptrdiff_t; //like gsl::index (https://github.com/microsoft/GSL)
42
43template< class Char >
44struct StringTraits;
45
46template<>
47struct StringTraits< char > {
48 template< class T >
49 static inline auto convertToString( T value ) -> std::string {
50 return std::to_string( value );
51 }
52};
53
54template<>
55struct StringTraits< wchar_t > {
56 template< class T >
57 static inline auto convertToString( T value ) -> std::wstring {
58 return std::to_wstring( value );
59 }
60};
67#ifdef _WIN32
69#define BIT7Z_NATIVE_STRING_( str ) L##str
70#define BIT7Z_NATIVE_STRING( str ) BIT7Z_NATIVE_STRING_( str )
71#else
73#define BIT7Z_NATIVE_STRING( str ) str
74#endif
75
79#if defined( BIT7Z_USE_NATIVE_STRING ) && defined( _WIN32 ) // Windows with native strings
80using tchar = wchar_t;
81#define BIT7Z_STRING( str ) BIT7Z_NATIVE_STRING_( str )
82#else // Unix, and Windows with non-native strings
83using tchar = char;
84#define BIT7Z_STRING( str ) str
85#endif
86
92
93#ifdef BIT7Z_REGEX_MATCHING
99#endif
100
101template< typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type >
102inline auto to_tstring( T arg ) -> std::basic_string< tchar > {
103 return StringTraits< tchar >::convertToString( arg );
104}
105
117#if defined( _WIN32 ) && !defined( BIT7Z_USE_NATIVE_STRING )
118auto to_tstring( const native_string& str ) -> tstring;
119#else
120auto to_tstring( const native_string& str ) -> const tstring&;
121#endif
122
123template< typename From, typename To >
126
127} // namespace bit7z
128
129#endif // BITTYPES_HPP
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:30
unsigned char byte_t
A type representing a byte.
Definition bittypes.hpp:36
char tchar
Definition bittypes.hpp:83
std::basic_string< tchar > tstring
Definition bittypes.hpp:91
std::string native_string
Native string type of the system.
Definition bittypes.hpp:72