bit7z 4.0.0
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};
66#ifdef _WIN32
68#define BIT7Z_NATIVE_STRING_( str ) L##str
69#define BIT7Z_NATIVE_STRING( str ) BIT7Z_NATIVE_STRING_( str )
70#else
72#define BIT7Z_NATIVE_STRING( str ) str
73#endif
74
78#if defined( BIT7Z_USE_NATIVE_STRING ) && defined( _WIN32 ) // Windows with native strings
79using tchar = wchar_t;
80#define BIT7Z_STRING( str ) BIT7Z_NATIVE_STRING_( str )
81#else // Unix, and Windows with non-native strings
82using tchar = char;
83#define BIT7Z_STRING( str ) str
84#endif
85
91
92#ifdef BIT7Z_REGEX_MATCHING
98#endif
99
100template< typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type >
101inline auto to_tstring( T arg ) -> std::basic_string< tchar > {
102 return StringTraits< tchar >::convertToString( arg );
103}
104
116#if defined( _WIN32 ) && !defined( BIT7Z_USE_NATIVE_STRING )
117auto to_tstring( const native_string& str ) -> tstring;
118#else
119auto to_tstring( const native_string& str ) -> const tstring&;
120#endif
121
122} // namespace bit7z
123
124#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:82
std::basic_string< tchar > tstring
Definition bittypes.hpp:90
std::string native_string
Native string type of the system.
Definition bittypes.hpp:71